Module: OCI::Auth::Util

Defined in:
lib/oci/auth/util.rb

Overview

Contains utility methods to support functionality in the OCI::Auth module, for example being able to extract information from certificates and scrubbing certificate information for calls to Auth Service

Class Method Summary collapse

Class Method Details

.colon_separate_fingerprint(raw_fingerprint) ⇒ Object



22
23
24
# File 'lib/oci/auth/util.rb', line 22

def self.colon_separate_fingerprint(raw_fingerprint)
  raw_fingerprint.gsub(/(.{2})(?=.)/, '\1:\2')
end

.get_tenancy_id_from_certificate(x509_certificate) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/oci/auth/util.rb', line 8

def self.get_tenancy_id_from_certificate(x509_certificate)
  subject_array = x509_certificate.subject.to_a
  subject_array.each do |subject_name|
    # subject_name is actually a triple like:
    #   ["OU", "<name>", "<number>"]
    if subject_name[0] == 'OU' && subject_name[1].include?('opc-tenant:')
      # 'opc-tenant:' is 11 character long, so we want to start at the index after that and to the end of the string (-1)
      return subject_name[1][11..-1]
    end
  end

  raise 'Certificate did not contain a tenancy in its subject'
end

.sanitize_certificate_string(cert_string) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/oci/auth/util.rb', line 26

def self.sanitize_certificate_string(cert_string)
  cert_string.gsub('-----BEGIN CERTIFICATE-----', '')
             .gsub('-----END CERTIFICATE-----', '')
             .gsub('-----BEGIN PUBLIC KEY-----', '')
             .gsub('-----END PUBLIC KEY-----', '')
             .delete("\n")
end