Class: Katello::Resources::Candlepin::CandlepinResource

Inherits:
HttpResource
  • Object
show all
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 inherited from HttpResource

#[], #[]=, hash_to_query, #initialize, issue_request, join_path, rest_client

Methods included from Concerns::FilterSensitiveData

#filter_sensitive_data

Constructor Details

This class inherits a constructor from Katello::HttpResource

Class Method Details

.default_headers(uuid = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/lib/katello/resources/candlepin.rb', line 38

def self.default_headers(uuid = nil)
  # There are cases where virt-who needs to act on behalf of hypervisors it is managing.
  # If the uuid is specified, then that consumer is used in the headers rather than the
  # virt-who consumer uuid.
  # Current example is creating a hypervisor that in turn needs to get compliance.
  if !uuid.nil? && User.consumer?
    cp_oauth_header = { 'cp-consumer' => uuid }
  else
    cp_oauth_header = User.cp_oauth_header
  end

  headers = {'accept' => 'application/json',
             'accept-language' => I18n.locale,
             'content-type' => 'application/json'}

  request_id = ::Logging.mdc['request']
  headers['X-Correlation-ID'] = request_id if request_id

  headers.merge!(cp_oauth_header)
end

.fetch_paged(page_size = -1)) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/lib/katello/resources/candlepin.rb', line 67

def self.fetch_paged(page_size = -1)
  if page_size == -1
    page_size = SETTINGS[:katello][:candlepin][:bulk_load_size]
  end
  page = 0
  content = []
  loop do
    page += 1
    data = yield("per_page=#{page_size}&page=#{page}")
    content.concat(data)
    break if data.size < page_size
  end
  content
end

.included_list(included) ⇒ Object



63
64
65
# File 'app/lib/katello/resources/candlepin.rb', line 63

def self.included_list(included)
  included.map { |value| "include=#{value}" }.join('&')
end

.loggerObject



34
35
36
# File 'app/lib/katello/resources/candlepin.rb', line 34

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

.name_to_key(a_name) ⇒ Object



59
60
61
# File 'app/lib/katello/resources/candlepin.rb', line 59

def self.name_to_key(a_name)
  a_name.tr(' ', '_')
end

.process_response(response) ⇒ Object



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

def process_response(response)
  debug_level = response.code >= 400 ? :error : :debug
  logger.send(debug_level, "Candlepin request #{response.headers[:x_candlepin_request_uuid]} returned with code #{response.code}")
  super
end

.raise_rest_client_exception(error, path, http_method) ⇒ Object



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

def raise_rest_client_exception(error, path, http_method)
  # this differentiates between Tomcat returning a 404 (candlepin is down or not deployed)
  # vs a 404 from Candlepin itself
  unless error&.response&.headers&.dig(:x_version)
    fail ::Katello::Errors::CandlepinNotRunning
  end

  super
end