Class: Api::Rhsm::CandlepinProxiesController
Instance Method Summary
collapse
-
#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
-
#get ⇒ 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_package_profile ⇒ Object
api :PUT, “/consumers/:id/packages”, N_(“Update installed packages”) api :PUT, “/consumers/:id/profile”, N_(“Update installed packages”) param :id, String, :desc => N_(“UUID of the consumer”), :required => true.
#add_candlepin_version_header, #authenticate_client, #cert_from_request, #cert_present?, #set_client_user
Instance Method Details
#available_releases ⇒ Object
140
141
142
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 140
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
216
217
218
219
220
221
222
223
224
225
226
227
228
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 216
def consumer_activate
User.current = User.anonymous_admin
activation_keys = find_activation_keys
host = Katello::Host::SubscriptionFacet.find_or_create_host(params[:facts]['network.hostname'],
activation_keys.first.organization, rhsm_params)
sync_task(::Actions::Katello::Host::Register, host, System.new, rhsm_params, nil, activation_keys)
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”)
124
125
126
127
128
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 124
def consumer_checkin
@host.update_attributes(:last_checkin => params[:date])
Candlepin::Consumer.new(@host.subscription_facet.uuid).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”)
193
194
195
196
197
198
199
200
201
202
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 193
def consumer_create
content_view_environment = find_content_view_environment
host = Katello::Host::SubscriptionFacet.find_or_create_host(params[:facts]['network.hostname'],
content_view_environment.environment.organization, rhsm_params)
sync_task(::Actions::Katello::Host::Register, host, System.new, rhsm_params, content_view_environment)
host.reload
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
206
207
208
209
210
211
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 206
def consumer_destroy
User.as_anonymous_admin do
sync_task(::Actions::Katello::Host::Unregister, @host)
end
render :text => _("Deleted consumer '%s'") % params[:id], :status => 204
end
|
#consumer_show ⇒ Object
api :GET, “/consumers/:id”, N_(“Show a system”) param :id, String, :desc => N_(“UUID of the consumer”), :required => true
92
93
94
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 92
def consumer_show
render :json => Resources::Candlepin::Consumer.get(params[:id])
end
|
#delete ⇒ Object
72
73
74
75
76
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 72
def delete
r = Resources::Candlepin::Proxy.delete(@request_path, @request_body.read)
logger.debug r
render :json => r
end
|
#drop_api_namespace(original_request_path) ⇒ Object
61
62
63
64
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 61
def drop_api_namespace(original_request_path)
prefix = "/rhsm"
original_request_path.gsub(prefix, '')
end
|
#enabled_repos ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 170
def enabled_repos
repos_params = params['enabled_repos'] rescue raise(HttpErrors::BadRequest, _("Expected attribute is missing:") + " enabled_repos")
repos_params = repos_params['repos'] || []
paths = repos_params.map do |repo|
if !repo['baseurl'].blank?
URI(repo['baseurl'].first).path
else
logger.warn("System #{@host.name} (#{@host.id}) attempted to bind to unspecific repo (#{repo}).")
nil
end
end
result = nil
User.as_anonymous_admin do
@host.content_host.save_bound_repos_by_path!(paths.compact)
result = @host.content_facet.update_repositories_by_paths(paths.compact)
end
respond_for_show :resource => result
end
|
#facts ⇒ Object
244
245
246
247
248
249
250
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 244
def facts
User.as_anonymous_admin do
sync_task(::Actions::Katello::Host::Update, @host, rhsm_params)
Katello::Host::SubscriptionFacet.update_facts(@host, rhsm_params[:facts]) unless rhsm_params[:facts].nil?
end
render :json => {:content => _("Facts successfully updated.")}, :status => 200
end
|
#get ⇒ Object
66
67
68
69
70
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 66
def get
r = Resources::Candlepin::Proxy.get(@request_path)
logger.debug r
render :json => r
end
|
#hypervisors_update ⇒ Object
api :POST, “/hypervisors”, N_(“Update the hypervisors information for environment”) desc ‘See virt-who tool for more details.’
113
114
115
116
117
118
119
120
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 113
def hypervisors_update
login = User.consumer? ? User.anonymous_api_admin.login : User.current.login
task = User.as(login) do
sync_task(::Actions::Katello::Host::Hypervisors, @environment, @content_view,
params.except(:controller, :action, :format))
end
render :json => task.output[:results]
end
|
#list_owners ⇒ Object
144
145
146
147
148
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 144
def list_owners
orgs = User.current.allowed_organizations
respond_for_index :collection => orgs.map { |o| { :key => o.label, :displayName => o.name } }
end
|
#post ⇒ Object
78
79
80
81
82
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 78
def post
r = Resources::Candlepin::Proxy.post(@request_path, @request_body.read)
logger.debug r
render :json => r
end
|
#proxy_request_body ⇒ Object
57
58
59
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 57
def proxy_request_body
@request_body = @_request.body
end
|
#proxy_request_path ⇒ Object
53
54
55
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 53
def proxy_request_path
@request_path = drop_api_namespace(@_request.fullpath)
end
|
#put ⇒ Object
84
85
86
87
88
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 84
def put
r = Resources::Candlepin::Proxy.put(@request_path, @request_body.read)
logger.debug 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 26
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”)
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 97
def rhsm_index
organization = find_organization
@all_environments = get_content_view_environments(params[:name], organization).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
252
253
254
255
256
|
# File 'app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb', line 252
def serials
@host.subscription_facet.last_checkin = DateTime.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”)
#upload_package_profile ⇒ Object
api :PUT, “/consumers/:id/packages”, N_(“Update installed packages”) api :PUT, “/consumers/:id/profile”, N_(“Update installed packages”) param :id, String, :desc => N_(“UUID of the consumer”), :required => true