Class: Katello::Api::V2::SubscriptionsController

Inherits:
ApiController
  • Object
show all
Includes:
Concerns::FilteredAutoCompleteSearch
Defined in:
app/controllers/katello/api/v2/subscriptions_controller.rb

Constant Summary

Constants included from Concerns::FilteredAutoCompleteSearch

Concerns::FilteredAutoCompleteSearch::PAGE_SIZE

Instance Method Summary collapse

Methods included from Concerns::FilteredAutoCompleteSearch

#auto_complete_search

Methods inherited from ApiController

#full_result_response, #scoped_search

Methods included from Rendering

#respond_for_async, #respond_for_bulk_async, #respond_for_create, #respond_for_destroy, #respond_for_index, #respond_for_show, #respond_for_status, #respond_for_update, #respond_with_template, #respond_with_template_collection, #respond_with_template_resource, #try_specific_collection_template, #try_specific_resource_template

Methods included from Katello::Api::Version2

#api_version

Instance Method Details

#createObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 60

def create
  if params[:subscriptions]
    params[:subscriptions].each do |sub|
      subscription = Pool.find(sub[:id])
      @activation_key.subscribe(subscription.cp_id, subscription[:quantity])
    end
  elsif params[:id] && params.key?(:quantity)
    sub = subscription.find(params[:id])
    @activation_key.subscribe(sub.cp_id, params[:quantity])
  end

  subscriptions = index_activation_key
  respond_for_index(:collection => subscriptions, :template => 'index')
end

#delete_manifestObject



120
121
122
123
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 120

def delete_manifest
  task = async_task(::Actions::Katello::Provider::ManifestDelete, @provider)
  respond_for_async :resource => task
end

#destroyObject



78
79
80
81
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 78

def destroy
  @activation_key.unsubscribe(params[:id])
  respond_for_index(:collection => scoped_search(import_subscriptions.uniq, :cp_id, :asc, :resource_class => Pool), :template => "index")
end

#for_hostObject



132
133
134
135
136
137
138
139
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 132

def for_host
  match_attached = params[:available_for] != "host"
  params[:match_host] = ::Foreman::Cast.to_bool(params[:match_host]) if params[:match_host]
  params[:match_installed] = ::Foreman::Cast.to_bool(params[:match_installed]) if params[:match_installed]
  params[:no_overlap] = ::Foreman::Cast.to_bool(params[:no_overlap]) if params[:no_overlap]

  @host.subscription_facet.candlepin_consumer.filtered_pools(match_attached, params[:match_host], params[:match_installed], params[:no_overlap])
end

#indexObject



30
31
32
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 30

def index
  respond(:collection => scoped_search(index_relation.uniq, :cp_id, :asc, :resource_class => Pool, :includes => [:subscription]))
end

#index_relationObject



34
35
36
37
38
39
40
41
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 34

def index_relation
  return for_host if params[:host_id]
  return available_for_activation_key if params[:available_for] == "activation_key"
  collection = Pool.readable
  collection = collection.where(:unmapped_guest => false)
  collection = collection.get_for_organization(Organization.find(params[:organization_id])) if params[:organization_id]
  collection
end

#manifest_historyObject



127
128
129
130
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 127

def manifest_history
  @manifest_history = @organization.manifest_history
  respond_with_template_collection(params[:action], "subscriptions", collection: @manifest_history)
end

#refresh_manifestObject



110
111
112
113
114
115
116
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 110

def refresh_manifest
  details  = @provider.organization.owner_details
  upstream = details['upstreamConsumer'].blank? ? {} : details['upstreamConsumer']

  task = async_task(::Actions::Katello::Provider::ManifestRefresh, @provider, upstream)
  respond_for_async :resource => task
end

#showObject



47
48
49
50
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 47

def show
  @resource = Katello::Pool.with_identifier(params[:id])
  respond(:resource => @resource)
end

#uploadObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 87

def upload
  fail HttpErrors::BadRequest, _("No manifest file uploaded") if params[:content].blank?

  begin
    # candlepin requires that the file has a zip file extension
    temp_file = File.new(File.join("#{Rails.root}/tmp", "import_#{SecureRandom.hex(10)}.zip"), 'wb+', 0600)
    temp_file.write params[:content].read
  ensure
    temp_file.close
  end

  # repository url
  if repo_url = params[:repository_url]
    @provider.repository_url = repo_url
    @provider.save!
  end

  task = async_task(::Actions::Katello::Provider::ManifestImport, @provider, File.expand_path(temp_file.path), params[:force])
  respond_for_async :resource => task
end