Sha256: 972663f1ad292d3666a182b634318c3b69ab1f2eaf77673a2181e1fd7507460d

Contents?: true

Size: 1.28 KB

Versions: 48

Compression:

Stored size: 1.28 KB

Contents

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

module PactBroker
  module Certificates
    module Service

      extend self
      extend PactBroker::Logging
      include 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

48 entries across 48 versions & 1 rubygems

Version Path
pact_broker-2.60.1 lib/pact_broker/certificates/service.rb
pact_broker-2.60.0 lib/pact_broker/certificates/service.rb
pact_broker-2.59.2 lib/pact_broker/certificates/service.rb
pact_broker-2.59.1 lib/pact_broker/certificates/service.rb
pact_broker-2.59.0 lib/pact_broker/certificates/service.rb
pact_broker-2.58.3 lib/pact_broker/certificates/service.rb
pact_broker-2.58.2 lib/pact_broker/certificates/service.rb
pact_broker-2.58.0 lib/pact_broker/certificates/service.rb
pact_broker-2.57.0 lib/pact_broker/certificates/service.rb
pact_broker-2.56.1 lib/pact_broker/certificates/service.rb
pact_broker-2.56.0 lib/pact_broker/certificates/service.rb
pact_broker-2.55.0 lib/pact_broker/certificates/service.rb
pact_broker-2.54.0 lib/pact_broker/certificates/service.rb
pact_broker-2.53.0 lib/pact_broker/certificates/service.rb
pact_broker-2.52.2 lib/pact_broker/certificates/service.rb
pact_broker-2.52.1 lib/pact_broker/certificates/service.rb
pact_broker-2.52.0 lib/pact_broker/certificates/service.rb
pact_broker-2.51.0 lib/pact_broker/certificates/service.rb
pact_broker-2.50.1 lib/pact_broker/certificates/service.rb
pact_broker-2.50.0 lib/pact_broker/certificates/service.rb