Class: Katello::Resources::Candlepin::Proxy

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

Class Method Summary collapse

Class Method Details

.default_request_headersObject



41
42
43
# File 'app/lib/katello/resources/candlepin/proxy.rb', line 41

def self.default_request_headers
  @default_request_headers ||= User.cp_oauth_header.merge(accept: :json)
end

.delete(path, body = nil) ⇒ Object



15
16
17
18
19
20
21
# File 'app/lib/katello/resources/candlepin/proxy.rb', line 15

def self.delete(path, body = nil)
  logger.debug "Sending DELETE request to Candlepin: #{path}"
  client = CandlepinResource.rest_client(Net::HTTP::Delete, :delete, path_with_cp_prefix(path))
  # Some candlepin calls will set the body in DELETE requests.
  client.options[:payload] = body unless body.nil?
  client.delete({:accept => :json, :content_type => :json}.merge(User.cp_oauth_header))
end

.get(path, extra_headers = {}) ⇒ Object



23
24
25
26
27
28
29
# File 'app/lib/katello/resources/candlepin/proxy.rb', line 23

def self.get(path, extra_headers = {})
  logger.debug "Sending GET request to Candlepin: #{path}"
  client = CandlepinResource.rest_client(Net::HTTP::Get, :get, path_with_cp_prefix(path))
  client.get(extra_headers.merge!(default_request_headers))
rescue RestClient::NotModified => e
  e.response
end

.loggerObject



5
6
7
# File 'app/lib/katello/resources/candlepin/proxy.rb', line 5

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

.path_with_cp_prefix(path) ⇒ Object



37
38
39
# File 'app/lib/katello/resources/candlepin/proxy.rb', line 37

def self.path_with_cp_prefix(path)
  CandlepinResource.prefix + path
end

.post(path, body) ⇒ Object



9
10
11
12
13
# File 'app/lib/katello/resources/candlepin/proxy.rb', line 9

def self.post(path, body)
  logger.debug "Sending POST request to Candlepin: #{path}"
  client = CandlepinResource.rest_client(Net::HTTP::Post, :post, path_with_cp_prefix(path))
  client.post body, {:accept => :json, :content_type => :json}.merge(User.cp_oauth_header)
end

.put(path, body) ⇒ Object



31
32
33
34
35
# File 'app/lib/katello/resources/candlepin/proxy.rb', line 31

def self.put(path, body)
  logger.debug "Sending PUT request to Candlepin: #{path}"
  client = CandlepinResource.rest_client(Net::HTTP::Put, :put, path_with_cp_prefix(path))
  client.put body, {:accept => :json, :content_type => :json}.merge(User.cp_oauth_header)
end