Class: Katello::Api::V2::RepositoriesController
Constant Summary
Concerns::FilteredAutoCompleteSearch::PAGE_SIZE
Instance Method Summary
collapse
#auto_complete_search
#full_result_response, #resource_class, #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
#api_version
Instance Method Details
#create ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 120
def create
repo_params = repository_params
unless RepositoryTypeManager.creatable_by_user?(repo_params[:content_type])
msg = _("Invalid params provided - content_type must be one of %s") % RepositoryTypeManager.creatable_repository_types.keys.join(",")
fail HttpErrors::UnprocessableEntity, msg
end
gpg_key = @product.gpg_key
unless repo_params[:gpg_key_id].blank?
gpg_key = @gpg_key
end
repo_params[:label] = labelize_params(repo_params)
repo_params[:url] = nil if repo_params[:url].blank?
unprotected = repo_params.key?(:unprotected) ? repo_params[:unprotected] : true
repository = @product.add_repo(repo_params[:label], repo_params[:name], repo_params[:url],
repo_params[:content_type], unprotected,
gpg_key, repository_params[:checksum_type], repo_params[:download_policy])
repository.docker_upstream_name = repo_params[:docker_upstream_name] if repo_params[:docker_upstream_name]
repository.mirror_on_sync = ::Foreman::Cast.to_bool(repo_params[:mirror_on_sync]) if repo_params[:mirror_on_sync]
sync_task(::Actions::Katello::Repository::Create, repository, false, true)
repository = Repository.find(repository.id)
respond_for_show(:resource => repository)
end
|
#destroy ⇒ Object
220
221
222
223
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 220
def destroy
sync_task(::Actions::Katello::Repository::Destroy, @repository)
respond_for_destroy
end
|
#export ⇒ Object
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 181
def export
if !params[:export_to_iso].present? && params[:iso_mb_size].present?
fail HttpErrors::BadRequest, _("ISO export must be enabled when specifying ISO size")
end
if params[:since].present?
begin
params[:since].to_datetime
rescue
raise HttpErrors::BadRequest, _("Invalid date provided.")
end
end
task = async_task(::Actions::Katello::Repository::Export, [@repository],
::Foreman::Cast.to_bool(params[:export_to_iso]),
params[:since].try(:to_datetime),
params[:iso_mb_size],
@repository.pulp_id)
respond_for_async :resource => task
end
|
#gpg_key_content ⇒ Object
312
313
314
315
316
317
318
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 312
def gpg_key_content
if @repository.gpg_key && @repository.gpg_key.content.present?
render(:text => @repository.gpg_key.content, :layout => false)
else
head(404)
end
end
|
#import_uploads ⇒ Object
295
296
297
298
299
300
301
302
303
304
305
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 295
def import_uploads
params[:upload_ids].each do |upload_id|
begin
sync_task(::Actions::Katello::Repository::ImportUpload, @repository, upload_id)
rescue => e
raise HttpErrors::BadRequest, e.message
end
end
render :nothing => true
end
|
#index ⇒ Object
52
53
54
55
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 52
def index
options = {:includes => [:gpg_key, :product, :environment]}
respond(:collection => scoped_search(index_relation.uniq, :name, :desc, options))
end
|
#index_relation ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 57
def index_relation
query = Repository.readable
query = index_relation_product(query)
query = query.where(:content_type => params[:content_type]) if params[:content_type]
query = query.where(:name => params[:name]) if params[:name]
if params[:erratum_id]
query = query.joins(:errata).where("#{Erratum.table_name}.id" => Erratum.with_identifiers(params[:erratum_id]))
end
if params[:rpm_id]
query = query.joins(:rpms).where("#{Rpm.table_name}.id" => Rpm.with_identifiers(params[:rpm_id]))
end
if params[:puppet_module_id]
query = query
.joins(:puppet_modules)
.where("#{PuppetModule.table_name}.id" => PuppetModule.with_identifiers(params[:puppet_module_id]))
end
query = index_relation_content_view(query)
query = index_relation_environment(query)
query
end
|
#index_relation_content_view(query) ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 89
def index_relation_content_view(query)
if params[:content_view_version_id]
query = query.where(:content_view_version_id => params[:content_view_version_id])
query = Repository.where(:id => query.map(&:library_instance_id)) if params[:library]
elsif params[:content_view_id]
query = filter_by_content_view(query, params[:content_view_id], params[:environment_id], params[:available_for] == 'content_view')
end
query
end
|
#index_relation_environment(query) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 99
def index_relation_environment(query)
if params[:environment_id] && !params[:library]
query = query.where(:environment_id => params[:environment_id])
elsif params[:environment_id] && params[:library]
instances = query.where(:environment_id => params[:environment_id])
instance_ids = instances.pluck(:library_instance_id).reject(&:blank?)
instance_ids += instances.where(:library_instance_id => nil)
query = Repository.where(:id => instance_ids)
elsif (params[:library] && !params[:environment_id]) || (params[:environment_id].blank? && params[:content_view_version_id].blank? && params[:content_view_id].blank?)
if @organization
query = query.where(:content_view_version_id => @organization.default_content_view.versions.first.id)
else
query = query.in_default_view
end
end
query
end
|
#index_relation_product(query) ⇒ Object
83
84
85
86
87
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 83
def index_relation_product(query)
query = query.joins(:product).where("#{Product.table_name}.organization_id" => @organization) if @organization
query = query.where(:product_id => @product.id) if @product
query
end
|
#remove_content ⇒ Object
260
261
262
263
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 260
def remove_content
fail _("No content ids provided") if @content.blank?
respond_for_async :resource => sync_task(::Actions::Katello::Repository::RemoveContent, @repository, @content)
end
|
#repository_types ⇒ Object
#show ⇒ Object
154
155
156
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 154
def show
respond_for_show(:resource => @repository)
end
|
#sync ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 162
def sync
if params[:source_url].present? && params[:source_url] !~ /\A#{URI.regexp}\z/
fail HttpErrors::BadRequest, _("source URL is malformed")
end
if params[:source_url].blank? && @repository.url.blank?
fail HttpErrors::BadRequest, _("attempted to sync without a feed URL")
end
task = async_task(::Actions::Katello::Repository::Sync, @repository,
nil, params[:source_url], ::Foreman::Cast.to_bool(params[:incremental]))
respond_for_async :resource => task
end
|
#sync_complete ⇒ Object
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 234
def sync_complete
if params[:token] != Rack::Utils.parse_query(URI(SETTINGS[:katello][:post_sync_url]).query)['token']
fail Errors::SecurityViolation, _("Token invalid during sync_complete.")
end
repo_id = params['payload']['repo_id']
task_id = params['call_report']['task_id']
User.current = User.anonymous_admin
repo = Repository.where(:pulp_id => repo_id).first
fail _("Couldn't find repository '%s'") % repo_id if repo.nil?
Rails.logger.info("Sync_complete called for #{repo.name}, running after_sync.")
unless repo.dynflow_handled_last_sync?(task_id)
async_task(::Actions::Katello::Repository::Sync, repo, task_id)
end
render :json => {}
end
|
#update ⇒ Object
212
213
214
215
216
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 212
def update
repo_params = repository_params
sync_task(::Actions::Katello::Repository::Update, @repository, repo_params)
respond_for_show(:resource => @repository)
end
|
#upload_content ⇒ Object
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
# File 'app/controllers/katello/api/v2/repositories_controller.rb', line 268
def upload_content
fail Katello::Errors::InvalidRepositoryContent, _("Cannot upload Docker content.") if @repository.docker?
filepaths = Array.wrap(params[:content]).compact.collect do |content|
{path: content.path, filename: content.original_filename}
end
if !filepaths.blank?
sync_task(::Actions::Katello::Repository::UploadFiles, @repository, filepaths)
render :json => {:status => "success"}
else
fail HttpErrors::BadRequest, _("No file uploaded")
end
rescue Katello::Errors::InvalidRepositoryContent => error
respond_for_exception(
error,
:status => :unprocessable_entity,
:text => error.message,
:errors => [error.message],
:with_logging => true
)
end
|