Module: ForemanRhCloud::CertAuth

Instance Method Summary collapse

Methods included from InsightsCloud::CandlepinCache

#candlepin_id_cert, #cp_owner_id, #upstream_owner

Instance Method Details

#cert_auth_available?(organization) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'app/services/foreman_rh_cloud/cert_auth.rb', line 8

def cert_auth_available?(organization)
  !!candlepin_id_cert(organization)
end

#execute_cloud_request(params) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/foreman_rh_cloud/cert_auth.rb', line 12

def execute_cloud_request(params)
  organization = params.delete(:organization)
  # Cache the value of with_iop_smart_proxy? to avoid multiple calls to the database
  with_iop_smart_proxy = ForemanRhCloud.with_iop_smart_proxy?
  certs = with_iop_smart_proxy ? foreman_certificate : candlepin_id_cert(organization)
  default_params = {
    ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
    ssl_client_key: OpenSSL::PKey.read(certs[:key]),
  }

  if with_iop_smart_proxy && organization&.label
    default_params[:headers] = {
      'X-Org-Id' => organization&.label,
    }
  end

  final_params = default_params.deep_merge(params)

  super(final_params)
end

#foreman_certificateObject



33
34
35
36
37
38
# File 'app/services/foreman_rh_cloud/cert_auth.rb', line 33

def foreman_certificate
  @foreman_certificate ||= {
    cert: File.read(Setting[:ssl_certificate]),
    key: File.read(Setting[:ssl_priv_key]),
  }
end