Class: Katello::Resources::Candlepin::UpstreamConsumer

Inherits:
HttpResource
  • Object
show all
Defined in:
app/lib/katello/resources/candlepin.rb

Instance Attribute Summary

Attributes inherited from HttpResource

#json

Class Method Summary collapse

Methods inherited from HttpResource

#[], #[]=, create_thing, delete, get, hash_to_query, #initialize, join_path, post, print_debug_info, process_response, put, raise_rest_client_exception, rest_client, url_encode

Constructor Details

This class inherits a constructor from Katello::HttpResource

Class Method Details

.export(url, client_cert, client_key, ca_file) ⇒ Object



289
290
291
292
293
294
295
296
# File 'app/lib/katello/resources/candlepin.rb', line 289

def self.export(url, client_cert, client_key, ca_file)
  logger.debug "Sending GET request to upstream Candlepin: #{url}"
  return resource(url, client_cert, client_key, ca_file).get
rescue => e
  raise e
ensure
  RestClient.proxy = ""
end

.loggerObject



263
264
265
# File 'app/lib/katello/resources/candlepin.rb', line 263

def self.logger
  ::Foreman::Logging.logger('katello/cp_rest')
end

.resource(url, client_cert, client_key, ca_file) ⇒ Object



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'app/lib/katello/resources/candlepin.rb', line 267

def self.resource(url, client_cert, client_key, ca_file)
  if SETTINGS[:katello][:cdn_proxy] && SETTINGS[:katello][:cdn_proxy][:host]
    proxy_config = SETTINGS[:katello][:cdn_proxy]
    uri = URI('')

    uri.scheme = URI.parse(proxy_config[:host]).scheme
    uri.host = URI.parse(proxy_config[:host]).host
    uri.port = proxy_config[:port]
    uri.user = proxy_config[:user]
    uri.password = proxy_config[:password]

    RestClient.proxy = uri.to_s
  end

  RestClient::Resource.new(url,
                           :ssl_client_cert => OpenSSL::X509::Certificate.new(client_cert),
                           :ssl_client_key => OpenSSL::PKey::RSA.new(client_key),
                           :ssl_ca_file => ca_file,
                           :verify_ssl => ca_file ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
  )
end

.update(url, client_cert, client_key, ca_file, attributes) ⇒ Object



298
299
300
301
302
303
304
305
306
307
# File 'app/lib/katello/resources/candlepin.rb', line 298

def self.update(url, client_cert, client_key, ca_file, attributes)
  logger.debug "Sending POST request to upstream Candlepin: #{url} #{attributes.to_json}"

  return resource(url, client_cert, client_key, ca_file).put(attributes.to_json,
                                                             'accept' => 'application/json',
                                                             'accept-language' => I18n.locale,
                                                             'content-type' => 'application/json')
ensure
  RestClient.proxy = ""
end