Sha256: 53026a5f7a8e777e0717d5a2432da7757bb26137e662817b01dcf03e37e47ff2

Contents?: true

Size: 1.25 KB

Versions: 23

Compression:

Stored size: 1.25 KB

Contents

require 'pact_broker/certificates/certificate'
require 'pact_broker/logging'
require 'openssl'

module PactBroker
  module Certificates
    module Service

      extend self
      extend PactBroker::Logging

      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

      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
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
pact_broker-2.27.2 lib/pact_broker/certificates/service.rb
pact_broker-2.27.0 lib/pact_broker/certificates/service.rb
pact_broker-2.26.1 lib/pact_broker/certificates/service.rb
pact_broker-2.26.0 lib/pact_broker/certificates/service.rb
pact_broker-2.25.0 lib/pact_broker/certificates/service.rb
pact_broker-2.24.0 lib/pact_broker/certificates/service.rb
pact_broker-2.23.4 lib/pact_broker/certificates/service.rb
pact_broker-2.23.3 lib/pact_broker/certificates/service.rb
pact_broker-2.23.2 lib/pact_broker/certificates/service.rb
pact_broker-2.23.1 lib/pact_broker/certificates/service.rb
pact_broker-2.23.0 lib/pact_broker/certificates/service.rb
pact_broker-2.22.0 lib/pact_broker/certificates/service.rb
pact_broker-2.21.0 lib/pact_broker/certificates/service.rb
pact_broker-2.20.0 lib/pact_broker/certificates/service.rb
pact_broker-2.19.2 lib/pact_broker/certificates/service.rb
pact_broker-2.19.1 lib/pact_broker/certificates/service.rb
pact_broker-2.19.0 lib/pact_broker/certificates/service.rb
pact_broker-2.18.0 lib/pact_broker/certificates/service.rb
pact_broker-2.17.1 lib/pact_broker/certificates/service.rb
pact_broker-2.17.0 lib/pact_broker/certificates/service.rb