Module: PactBroker::Certificates::Service

Extended by:
Service, Logging
Included in:
Service
Defined in:
lib/pact_broker/certificates/service.rb

Constant Summary

Constants included from Logging

Logging::LOG_DIR, Logging::LOG_FILE_NAME

Instance Method Summary collapse

Methods included from Logging

included, log_error, logger, logger=

Instance Method Details

#cert_storeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pact_broker/certificates/service.rb', line 12

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
      log_error e, "Error adding certificate object #{certificate.to_s} to store"
    end
  end
  cert_store
end

#find_all_certificatesObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pact_broker/certificates/service.rb', line 26

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
        log_error e, "Error creating certificate object from certificate #{certificate.uuid} '#{certificate.description}'"
        nil
      end
    end
  end.flatten.compact
end