Sha256: c4d8b15e9aaeec829d7f566f1d0b247e45fb97eaddcb6b2c5000dade3d55afc1

Contents?: true

Size: 824 Bytes

Versions: 173

Compression:

Stored size: 824 Bytes

Contents

require 'openssl'
require 'base64'

module Cert
  class RhsmClient
    attr_accessor :cert

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

    def uuid
      drop_cn_prefix_from_subject(@cert.subject.to_s)
    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 drop_cn_prefix_from_subject(subject_string)
      subject_string.sub(/\/CN=/i, '')
    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

173 entries across 173 versions & 1 rubygems

Version Path
katello-4.2.2 app/services/cert/rhsm_client.rb
katello-4.3.0 app/services/cert/rhsm_client.rb
katello-4.3.0.rc4 app/services/cert/rhsm_client.rb
katello-4.3.0.rc3 app/services/cert/rhsm_client.rb
katello-4.3.0.rc2.1 app/services/cert/rhsm_client.rb
katello-4.3.0.rc2 app/services/cert/rhsm_client.rb
katello-4.3.0.rc1 app/services/cert/rhsm_client.rb
katello-4.2.1 app/services/cert/rhsm_client.rb
katello-4.2.0.1 app/services/cert/rhsm_client.rb
katello-4.1.4 app/services/cert/rhsm_client.rb
katello-4.0.3 app/services/cert/rhsm_client.rb
katello-4.2.0.1.rc3 app/services/cert/rhsm_client.rb
katello-3.18.5 app/services/cert/rhsm_client.rb
katello-4.2.0.1.rc2 app/services/cert/rhsm_client.rb
katello-4.2.0.rc2 app/services/cert/rhsm_client.rb
katello-4.1.3 app/services/cert/rhsm_client.rb
katello-4.2.0.rc1 app/services/cert/rhsm_client.rb
katello-4.0.2.1 app/services/cert/rhsm_client.rb
katello-4.1.2.1 app/services/cert/rhsm_client.rb
katello-4.0.2 app/services/cert/rhsm_client.rb