module PactBroker::Certificates::Service

Public Instance Methods

cert_store() click to toggle source
# File lib/pact_broker/certificates/service.rb, line 13
def cert_store
  cert_store = OpenSSL::X509::Store.new
  cert_store.set_default_paths
  find_all_certificates.each do | certificate |
    begin
      logger.debug("Loading certificate #{certificate.subject} in to cert store")
      cert_store.add_cert(certificate)
    rescue StandardError => e
      logger.warn("Error adding certificate object #{certificate} to store", e)
    end
  end
  cert_store
end
find_all_certificates() click to toggle source
# File lib/pact_broker/certificates/service.rb, line 27
def find_all_certificates
  Certificate.collect do | certificate |
    cert_arr = certificate.content.split(/(-----END [^\-]+-----)/).each_slice(2).map(&:join).map(&:strip).select{|s| !s.empty?}
    cert_arr.collect do |c|
      begin
        OpenSSL::X509::Certificate.new(c)
      rescue StandardError => e
        logger.warn("Error creating certificate object from certificate #{certificate.uuid} '#{certificate.description}'", e)
        nil
      end
    end
  end.flatten.compact
end