Class: Katello::Resources::Candlepin::UpstreamCandlepinResource

Inherits:
CandlepinResource show all
Extended by:
Util::HttpProxy
Defined in:
app/lib/katello/resources/candlepin.rb

Constant Summary

Constants inherited from HttpResource

HttpResource::REQUEST_MAP

Instance Attribute Summary

Attributes inherited from HttpResource

#json

Class Method Summary collapse

Methods included from Util::HttpProxy

proxy, proxy_host, proxy_port, proxy_scheme, proxy_uri

Methods inherited from CandlepinResource

default_headers, fetch_paged, included_list, logger, name_to_key, process_response, raise_rest_client_exception

Methods inherited from HttpResource

#[], #[]=, hash_to_query, #initialize, issue_request, join_path, logger, process_response, raise_rest_client_exception

Methods included from Concerns::FilterSensitiveData

#filter_sensitive_data

Constructor Details

This class inherits a constructor from Katello::HttpResource

Class Method Details

.client_certObject



123
124
125
# File 'app/lib/katello/resources/candlepin.rb', line 123

def client_cert
  upstream_id_cert['cert']
end

.client_keyObject



127
128
129
# File 'app/lib/katello/resources/candlepin.rb', line 127

def client_key
  upstream_id_cert['key']
end

.json_resource(options = {}, url: self.site + self.path, client_cert: self.client_cert, client_key: self.client_key, ca_file: nil) ⇒ Object



110
111
112
113
# File 'app/lib/katello/resources/candlepin.rb', line 110

def json_resource(options = {}, url: self.site + self.path, client_cert: self.client_cert, client_key: self.client_key, ca_file: nil)
  options.deep_merge!(headers: self.default_headers)
  resource(options, url: url, client_cert: client_cert, client_key: client_key, ca_file: ca_file)
end

.resource(options = {}, url: self.site + self.path, client_cert: self.client_cert, client_key: self.client_key, ca_file: nil) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/lib/katello/resources/candlepin.rb', line 91

def resource(options = {}, url: self.site + self.path, client_cert: self.client_cert, client_key: self.client_key, ca_file: nil)
  cert_store = OpenSSL::X509::Store.new
  cert_store.add_file(ca_file) if ca_file

  if proxy&.cacert&.present?
    Foreman::Util.add_ca_bundle_to_store(proxy.cacert, cert_store)
  end
  RestClient::Resource.new(url,
                           :ssl_client_cert => OpenSSL::X509::Certificate.new(client_cert),
                           :ssl_client_key => OpenSSL::PKey::RSA.new(client_key),
                           :ssl_cert_store => cert_store,
                           :verify_ssl => ca_file ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE,
                           :open_timeout => Setting[:manifest_refresh_timeout],
                           :timeout => Setting[:manifest_refresh_timeout],
                           :proxy => self.proxy_uri,
                           **options
                          )
end

.rest_client(_http_type = nil, method = :get, path = self.path) ⇒ Object



115
116
117
118
119
120
121
# File 'app/lib/katello/resources/candlepin.rb', line 115

def rest_client(_http_type = nil, method = :get, path = self.path)
  # No oauth upstream
  self.consumer_secret = nil
  self.consumer_key = nil

  resource({ http_method: method }, url: self.site + path, client_cert: client_cert, client_key: client_key, ca_file: nil)
end

.siteObject



135
136
137
# File 'app/lib/katello/resources/candlepin.rb', line 135

def site
  "#{upstream_api_uri.scheme}://#{upstream_api_uri.host}"
end

.upstream_api_uriObject



131
132
133
# File 'app/lib/katello/resources/candlepin.rb', line 131

def upstream_api_uri
  URI.parse(upstream_consumer['apiUrl'])
end

.upstream_consumerObject



158
159
160
161
162
163
164
# File 'app/lib/katello/resources/candlepin.rb', line 158

def upstream_consumer
  fail _("Current organization not set.") unless Organization.current
  upstream_consumer = Organization.current.owner_details['upstreamConsumer']
  fail Katello::Errors::NoManifestImported unless upstream_consumer

  upstream_consumer
end

.upstream_consumer_idObject



154
155
156
# File 'app/lib/katello/resources/candlepin.rb', line 154

def upstream_consumer_id
  upstream_consumer['uuid']
end

.upstream_id_certObject



139
140
141
142
143
144
145
# File 'app/lib/katello/resources/candlepin.rb', line 139

def upstream_id_cert
  unless upstream_consumer && upstream_consumer['idCert'] && upstream_consumer['idCert']['cert'] && upstream_consumer['idCert']['key']
    Rails.logger.error "Upstream identity certificate not available"
    fail _("Upstream identity certificate not available")
  end
  upstream_consumer['idCert']
end

.upstream_owner_idObject



147
148
149
150
151
152
# File 'app/lib/katello/resources/candlepin.rb', line 147

def upstream_owner_id
  JSON.parse(Katello::Resources::Candlepin::UpstreamConsumer.resource.get.body)['owner']['key']
rescue RestClient::Exception => e
  Rails.logger.error "Unable to find upstream owner for consumer"
  raise e
end