Class: Api::Rhsm::CandlepinProxiesController
Overview
rubocop:disable Metrics/ClassLength
Constant Summary
collapse
'If-Modified-Since'.freeze
Instance Method Summary
collapse
-
#async_hypervisors_update ⇒ Object
api :POST, “/hypervisors/OWNER” Note that this request comes in as content-type ‘text/plain’ so that tomcat won’t parse the json.
-
#available_releases ⇒ Object
-
#consumer_activate ⇒ Object
used for registering with activation keys api :POST, “/consumers”, N_(“Register a system with activation key (compatibility)”) param :activation_keys, String, :required => true.
-
#consumer_checkin ⇒ Object
api :PUT, “/consumers/:id/checkin/”, N_(“Update consumer check-in time”) param :date, String, :desc => N_(“check-in time”).
-
#consumer_create ⇒ Object
api :POST, “/environments/:environment_id/consumers”, N_(“Register a consumer in environment”).
-
#consumer_destroy ⇒ Object
api :DELETE, “/consumers/:id”, N_(“Unregister a consumer”) param :id, String, :desc => N_(“UUID of the consumer”), :required => true.
-
#consumer_show ⇒ Object
api :GET, “/consumers/:id”, N_(“Show a system”) param :id, String, :desc => N_(“UUID of the consumer”), :required => true.
-
#delete ⇒ Object
-
#drop_api_namespace(original_request_path) ⇒ Object
-
#enabled_repos ⇒ Object
-
#facts ⇒ Object
api :PUT, “/consumers/:id”, N_(“Update consumer information”).
-
#get ⇒ Object
-
#get_parent_host(headers) ⇒ Object
-
#hypervisors_heartbeat ⇒ Object
-
#hypervisors_update ⇒ Object
api :POST, “/hypervisors”, N_(“Update the hypervisors information for environment”) desc ‘See virt-who tool for more details.’.
-
#list_owners ⇒ Object
-
#post ⇒ Object
-
#proxy_request_body ⇒ Object
-
#proxy_request_path ⇒ Object
-
#put ⇒ Object
-
#regenerate_identity_certificates ⇒ Object
api :POST, “/consumers/:id”, N_(“Regenerate consumer identity”) param :id, String, :desc => N_(“UUID of the consumer”) desc ‘Schedules the consumer identity certificate regeneration’.
-
#repackage_message ⇒ Object
-
#rhsm_index ⇒ Object
api :GET, “/owners/:organization_id/environments”, N_(“List environments for RHSM”).
-
#serials ⇒ Object
-
#server_status ⇒ Object
api :GET, “/status”, N_(“Shows version information”) description N_(“This service is available for unauthenticated users”).
-
#upload_tracer_profile ⇒ Object
#add_candlepin_version_header, #authenticate_client, #cert_from_request, #cert_present?, #set_client_user
Instance Method Details
#async_hypervisors_update ⇒ Object
api :POST, “/hypervisors/OWNER” Note that this request comes in as content-type ‘text/plain’ so that tomcat won’t parse the json. Here we just pass the plain body through to candlepin
128
129
130
131
132
133
134
135
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 128
def async_hypervisors_update
task = Katello::Resources::Candlepin::Consumer.async_hypervisors(owner: params[:owner],
reporter_id: params[:reporter_id],
raw_json: request.raw_post)
async_task(::Actions::Katello::Host::Hypervisors, nil, :task_id => task['id'])
render :json => task
end
|
#available_releases ⇒ Object
170
171
172
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 170
def available_releases
render :json => @host.content_facet.try(:available_releases) || []
end
|
#consumer_activate ⇒ Object
used for registering with activation keys api :POST, “/consumers”, N_(“Register a system with activation key (compatibility)”) param :activation_keys, String, :required => true
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 235
def consumer_activate
User.current = User.anonymous_admin
additional_set_taxonomy
activation_keys = find_activation_keys
host = Katello::RegistrationManager.process_registration(rhsm_params, nil, activation_keys)
update_host_registered_through(host, request.)
host.reload
render :json => Resources::Candlepin::Consumer.get(host.subscription_facet.uuid)
end
|
#consumer_checkin ⇒ Object
api :PUT, “/consumers/:id/checkin/”, N_(“Update consumer check-in time”) param :date, String, :desc => N_(“check-in time”)
155
156
157
158
159
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 155
def consumer_checkin
@host.update(:last_checkin => params[:date])
Candlepin::Consumer.new(@host.subscription_facet.uuid, @host.organization.label).checkin(params[:date])
render :json => Resources::Candlepin::Consumer.get(@host.subscription_facet.uuid)
end
|
#consumer_create ⇒ Object
api :POST, “/environments/:environment_id/consumers”, N_(“Register a consumer in environment”)
213
214
215
216
217
218
219
220
221
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 213
def consumer_create
host = Katello::RegistrationManager.process_registration(rhsm_params, find_content_view_environments)
host.reload
update_host_registered_through(host, request.)
render :json => Resources::Candlepin::Consumer.get(host.subscription_facet.uuid)
end
|
#consumer_destroy ⇒ Object
api :DELETE, “/consumers/:id”, N_(“Unregister a consumer”) param :id, String, :desc => N_(“UUID of the consumer”), :required => true
225
226
227
228
229
230
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 225
def consumer_destroy
User.as_anonymous_admin do
Katello::RegistrationManager.unregister_host(@host, :unregistering => !Setting['unregister_delete_host'])
end
render :plain => _("Deleted consumer '%s'") % params[:id], :status => :no_content
end
|
#consumer_show ⇒ Object
api :GET, “/consumers/:id”, N_(“Show a system”) param :id, String, :desc => N_(“UUID of the consumer”), :required => true
107
108
109
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 107
def consumer_show
render :json => Resources::Candlepin::Consumer.get(params[:id])
end
|
#delete ⇒ Object
87
88
89
90
91
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 87
def delete
r = Resources::Candlepin::Proxy.delete(@request_path, @request_body.read)
logger.debug filter_sensitive_data(r)
render :json => r
end
|
#drop_api_namespace(original_request_path) ⇒ Object
70
71
72
73
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 70
def drop_api_namespace(original_request_path)
prefix = "/rhsm"
original_request_path.gsub(prefix, '')
end
|
#enabled_repos ⇒ Object
200
201
202
203
204
205
206
207
208
209
210
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 200
def enabled_repos
repos_params = params.dig('enabled_repos', 'repos')
fail(HttpErrors::BadRequest, _("The request did not contain any repository information.")) if repos_params.nil?
result = nil
User.as_anonymous_admin do
result = @host.import_enabled_repositories(repos_params)
end
respond_for_show :resource => result
end
|
#facts ⇒ Object
api :PUT, “/consumers/:id”, N_(“Update consumer information”)
259
260
261
262
263
264
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 259
def facts
User.current = User.anonymous_admin
@host.update_candlepin_associations(rhsm_params)
update_host_registered_through(@host, request.)
render :json => {:content => _("Facts successfully updated.")}, :status => :ok
end
|
#get ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 75
def get
= {}
modified_since = request.[IF_MODIFIED_SINCE_HEADER]
if modified_since.present?
[IF_MODIFIED_SINCE_HEADER] = modified_since
end
r = Resources::Candlepin::Proxy.get(@request_path, )
logger.debug filter_sensitive_data(r)
render :json => r, :status => r.code
end
|
#get_parent_host(headers) ⇒ Object
272
273
274
275
276
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 272
def get_parent_host()
hostnames = ["HTTP_X_FORWARDED_HOST"]
host = hostnames.split(/[,,:]/)[0].strip if hostnames
host || URI.parse(Setting[:foreman_url]).host
end
|
#hypervisors_heartbeat ⇒ Object
#hypervisors_update ⇒ Object
api :POST, “/hypervisors”, N_(“Update the hypervisors information for environment”) desc ‘See virt-who tool for more details.’
139
140
141
142
143
144
145
146
147
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 139
def hypervisors_update
login = User.consumer? ? User.anonymous_api_admin.login : User.current.login
task = User.as(login) do
params['owner'] = @organization.label params['env'] = nil sync_task(::Actions::Katello::Host::Hypervisors, params.except(:controller, :action, :format).to_h)
end
render :json => task.output[:results]
end
|
#list_owners ⇒ Object
174
175
176
177
178
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 174
def list_owners
orgs = User.current.allowed_organizations
respond_for_index :collection => orgs.map { |o| { :key => o.label, :displayName => o.name } }
end
|
#post ⇒ Object
93
94
95
96
97
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 93
def post
r = Resources::Candlepin::Proxy.post(@request_path, @request_body.read)
logger.debug filter_sensitive_data(r)
render :json => r
end
|
#proxy_request_body ⇒ Object
66
67
68
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 66
def proxy_request_body
@request_body = @_request.body
end
|
#proxy_request_path ⇒ Object
62
63
64
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 62
def proxy_request_path
@request_path = drop_api_namespace(@_request.fullpath)
end
|
#put ⇒ Object
99
100
101
102
103
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 99
def put
r = Resources::Candlepin::Proxy.put(@request_path, @request_body.read)
logger.debug filter_sensitive_data(r)
render :json => r
end
|
#regenerate_identity_certificates ⇒ Object
api :POST, “/consumers/:id”, N_(“Regenerate consumer identity”) param :id, String, :desc => N_(“UUID of the consumer”) desc ‘Schedules the consumer identity certificate regeneration’
#repackage_message ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 36
def repackage_message
yield
ensure
if response.status >= 400
begin
body_json = JSON.parse(response.body)
if body_json['message'] && body_json['displayMessage'].nil?
body_json['displayMessage'] = body_json['message']
end
response.body = body_json.to_s
rescue JSON::ParserError
end
end
end
|
#rhsm_index ⇒ Object
api :GET, “/owners/:organization_id/environments”, N_(“List environments for RHSM”)
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 112
def rhsm_index
@all_environments = get_content_view_environments(params[:name], Organization.current).collect do |env|
{
:id => env.cp_id,
:name => env.label,
:display_name => env.name,
:description => env.content_view.description
}
end
respond_for_index :collection => @all_environments
end
|
#serials ⇒ Object
266
267
268
269
270
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 266
def serials
@host.subscription_facet.last_checkin = Time.now
@host.subscription_facet.save!
render :json => Katello::Resources::Candlepin::Consumer.serials(@host.subscription_facet.uuid)
end
|
#server_status ⇒ Object
api :GET, “/status”, N_(“Shows version information”) description N_(“This service is available for unauthenticated users”)
252
253
254
255
256
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 252
def server_status
candlepin_response = Resources::Candlepin::CandlepinPing.ping
candlepin_response[:managerCapabilities] << 'combined_reporting'
render :json => candlepin_response
end
|
#upload_tracer_profile ⇒ Object
163
164
165
166
167
168
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 163
def upload_tracer_profile
User.as_anonymous_admin do
@host.import_tracer_profile(params[:traces])
end
render json: { displayMessage: _("Tracer profile uploaded successfully") }
end
|