Sha256: b657bb405d2bf917063c2ad935321d6c270ae2816cfef3ac60bfda9e0aa371cd

Contents?: true

Size: 750 Bytes

Versions: 71

Compression:

Stored size: 750 Bytes

Contents

require 'openssl'
require 'base64'

module Cert
  class RhsmClient
    attr_accessor :cert

    def initialize(cert)
      self.cert = extract(cert)
    end

    def uuid
      @uuid ||= @cert.subject.to_a.detect { |name, _, _| name == 'CN' }&.second
    end

    private

    def extract(cert)
      if cert.empty?
        fail('Invalid cert provided. Ensure that the provided cert is not empty.')
      else
        cert = strip_cert(cert)
        cert = Base64.decode64(cert)

        OpenSSL::X509::Certificate.new(cert)
      end
    end

    def strip_cert(cert)
      cert = cert.to_s.gsub("-----BEGIN CERTIFICATE-----", "").gsub("-----END CERTIFICATE-----", "")
      cert.delete!(' ')
      cert.gsub!(/\n/, '')
      cert
    end
  end
end

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
katello-4.16.0 app/services/cert/rhsm_client.rb
katello-4.15.1 app/services/cert/rhsm_client.rb
katello-4.16.0.rc2 app/services/cert/rhsm_client.rb
katello-4.16.0.rc1 app/services/cert/rhsm_client.rb
katello-4.14.3 app/services/cert/rhsm_client.rb
katello-4.14.2 app/services/cert/rhsm_client.rb
katello-4.15.0 app/services/cert/rhsm_client.rb
katello-4.15.0.rc2 app/services/cert/rhsm_client.rb
katello-4.15.0.rc1 app/services/cert/rhsm_client.rb
katello-4.14.1 app/services/cert/rhsm_client.rb
katello-4.14.0 app/services/cert/rhsm_client.rb
katello-4.14.0.rc3 app/services/cert/rhsm_client.rb
katello-4.14.0.rc2 app/services/cert/rhsm_client.rb
katello-4.14.0.rc1.1 app/services/cert/rhsm_client.rb
katello-4.14.0.rc1 app/services/cert/rhsm_client.rb
katello-4.13.1 app/services/cert/rhsm_client.rb
katello-4.13.0 app/services/cert/rhsm_client.rb
katello-4.12.1 app/services/cert/rhsm_client.rb
katello-4.13.0.rc1 app/services/cert/rhsm_client.rb
katello-4.12.0 app/services/cert/rhsm_client.rb