debian-mirror-gitlab/lib/api/package_files.rb

78 lines
2.4 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module API
2021-01-03 14:25:43 +05:30
class PackageFiles < ::API::Base
2020-07-28 23:09:34 +05:30
include PaginationParams
before do
authorize_packages_access!(user_project)
end
2023-01-13 00:05:48 +05:30
PACKAGE_FILES_TAGS = %w[package_files].freeze
2021-01-29 00:20:46 +05:30
feature_category :package_registry
2022-07-16 23:28:13 +05:30
urgency :low
2021-01-29 00:20:46 +05:30
2020-07-28 23:09:34 +05:30
helpers ::API::Helpers::PackagesHelpers
params do
2023-01-13 00:05:48 +05:30
requires :id, types: [String, Integer], desc: 'ID or URL-encoded path of the project'
requires :package_id, type: Integer, desc: 'ID of a package'
2020-07-28 23:09:34 +05:30
end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
2023-01-13 00:05:48 +05:30
desc 'List package files' do
detail 'Get a list of package files of a single package'
2020-07-28 23:09:34 +05:30
success ::API::Entities::PackageFile
2023-01-13 00:05:48 +05:30
is_array true
tags PACKAGE_FILES_TAGS
2020-07-28 23:09:34 +05:30
end
params do
use :pagination
end
2023-07-09 08:55:56 +05:30
route_setting :authentication, job_token_allowed: true
2020-07-28 23:09:34 +05:30
get ':id/packages/:package_id/package_files' do
package = ::Packages::PackageFinder
.new(user_project, params[:package_id]).execute
2022-04-04 11:22:00 +05:30
package_files = package.installable_package_files
2022-05-07 20:08:51 +05:30
.preload_pipelines.order_id_asc
2022-03-02 08:16:31 +05:30
present paginate(package_files), with: ::API::Entities::PackageFile
2020-07-28 23:09:34 +05:30
end
2021-06-08 01:23:25 +05:30
2023-01-13 00:05:48 +05:30
desc 'Delete a package file' do
2021-06-08 01:23:25 +05:30
detail 'This feature was introduced in GitLab 13.12'
2023-01-13 00:05:48 +05:30
success code: 204
failure [
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not found' }
]
tags PACKAGE_FILES_TAGS
2021-06-08 01:23:25 +05:30
end
params do
2023-01-13 00:05:48 +05:30
requires :package_file_id, type: Integer, desc: 'ID of a package file'
2021-06-08 01:23:25 +05:30
end
2023-07-09 08:55:56 +05:30
route_setting :authentication, job_token_allowed: true
2021-06-08 01:23:25 +05:30
delete ':id/packages/:package_id/package_files/:package_file_id' do
authorize_destroy_package!(user_project)
# We want to make sure the file belongs to the declared package
# so we look up the package before looking up the file.
package = ::Packages::PackageFinder
.new(user_project, params[:package_id]).execute
not_found! unless package
2022-04-04 11:22:00 +05:30
package_file = package.installable_package_files
.find_by_id(params[:package_file_id])
2021-06-08 01:23:25 +05:30
not_found! unless package_file
2022-03-02 08:16:31 +05:30
destroy_conditionally!(package_file) do |package_file|
package_file.pending_destruction!
end
2021-06-08 01:23:25 +05:30
end
2020-07-28 23:09:34 +05:30
end
end
end