Class: Api::Rhsm::CandlepinDynflowProxyController

Inherits:
V2::ApiController
  • Object
show all
Includes:
AbstractController::Callbacks, ForemanTasks::Triggers, Katello::Authentication::ClientAuthentication
Defined in:
app/controllers/katello/api/rhsm/candlepin_dynflow_proxy_controller.rb

Instance Method Summary collapse

Methods included from Katello::Authentication::ClientAuthentication

#add_candlepin_version_header, #authenticate_client, #cert_from_request, #cert_present?, #set_client_user

Instance Method Details

#authorize_client_or_userObject



64
65
66
# File 'app/controllers/katello/api/rhsm/candlepin_dynflow_proxy_controller.rb', line 64

def authorize_client_or_user
  client_authorized? || authorize
end

#client_authorized?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
# File 'app/controllers/katello/api/rhsm/candlepin_dynflow_proxy_controller.rb', line 68

def client_authorized?
  authorized = authenticate_client && User.consumer?
  authorized = (User.current.uuid == @host.subscription_facet.uuid) if @host && User.consumer?
  authorized
end

#find_host(uuid = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/katello/api/rhsm/candlepin_dynflow_proxy_controller.rb', line 42

def find_host(uuid = nil)
  params = request.path_parameters
  uuid ||= params[:id]
  facet = Katello::Host::SubscriptionFacet.where(:uuid => uuid).first
  if facet.nil?
    # check with candlepin if consumer is Gone, raises RestClient::Gone
    User.as_anonymous_admin { Resources::Candlepin::Consumer.get(uuid) }
    fail HttpErrors::NotFound, _("Couldn't find consumer '%s'") % uuid
  end
  @host = facet.host
end

#upload_package_profileObject

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



16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/katello/api/rhsm/candlepin_dynflow_proxy_controller.rb', line 16

def upload_package_profile
  User.as_anonymous_admin do
    uploader = ::Katello::Host::PackageProfileUploader.new(
      host: @host,
      profile_string: request.raw_post
    )
    uploader.upload
    uploader.trigger_applicability_generation
  end
  render :json => Resources::Candlepin::Consumer.get(@host.subscription_facet.uuid)
end

#upload_profilesObject



30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/katello/api/rhsm/candlepin_dynflow_proxy_controller.rb', line 30

def upload_profiles
  User.as_anonymous_admin do
    uploader = ::Katello::Host::ProfilesUploader.new(
      host: @host,
      profile_string: request.raw_post
    )
    uploader.upload
    uploader.trigger_applicability_generation
  end
  render :json => Resources::Candlepin::Consumer.get(@host.subscription_facet.uuid)
end