2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2021-01-03 14:25:43 +05:30
|
|
|
class ProjectPackages < ::API::Base
|
2020-07-28 23:09:34 +05:30
|
|
|
include PaginationParams
|
|
|
|
|
|
|
|
before do
|
|
|
|
authorize_packages_access!(user_project)
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
requires :id, type: String, desc: 'The ID of a project'
|
|
|
|
end
|
|
|
|
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
|
|
|
desc 'Get all project packages' do
|
|
|
|
detail 'This feature was introduced in GitLab 11.8'
|
|
|
|
success ::API::Entities::Package
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
use :pagination
|
|
|
|
optional :order_by, type: String, values: %w[created_at name version type], default: 'created_at',
|
|
|
|
desc: 'Return packages ordered by `created_at`, `name`, `version` or `type` fields.'
|
|
|
|
optional :sort, type: String, values: %w[asc desc], default: 'asc',
|
|
|
|
desc: 'Return packages sorted in `asc` or `desc` order.'
|
|
|
|
optional :package_type, type: String, values: Packages::Package.package_types.keys,
|
|
|
|
desc: 'Return packages of a certain type'
|
|
|
|
optional :package_name, type: String,
|
|
|
|
desc: 'Return packages with this name'
|
2021-03-08 18:12:59 +05:30
|
|
|
optional :include_versionless, type: Boolean,
|
2022-08-27 11:52:29 +05:30
|
|
|
desc: 'Returns packages without a version'
|
2021-03-11 19:13:27 +05:30
|
|
|
optional :status, type: String, values: Packages::Package.statuses.keys,
|
2022-08-27 11:52:29 +05:30
|
|
|
desc: 'Return packages with specified status'
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
route_setting :authentication, job_token_allowed: true
|
2020-07-28 23:09:34 +05:30
|
|
|
get ':id/packages' do
|
|
|
|
packages = ::Packages::PackagesFinder.new(
|
|
|
|
user_project,
|
2021-03-11 19:13:27 +05:30
|
|
|
declared_params.slice(:order_by, :sort, :package_type, :package_name, :include_versionless, :status)
|
2020-07-28 23:09:34 +05:30
|
|
|
).execute
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
present paginate(packages), with: ::API::Entities::Package, user: current_user, namespace: user_project.namespace
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Get a single project package' do
|
|
|
|
detail 'This feature was introduced in GitLab 11.9'
|
|
|
|
success ::API::Entities::Package
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :package_id, type: Integer, desc: 'The ID of a package'
|
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
route_setting :authentication, job_token_allowed: true
|
2020-07-28 23:09:34 +05:30
|
|
|
get ':id/packages/:package_id' do
|
|
|
|
package = ::Packages::PackageFinder
|
|
|
|
.new(user_project, params[:package_id]).execute
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
present package, with: ::API::Entities::Package, user: current_user, namespace: user_project.namespace
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Remove a package' do
|
|
|
|
detail 'This feature was introduced in GitLab 11.9'
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :package_id, type: Integer, desc: 'The ID of a package'
|
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
route_setting :authentication, job_token_allowed: true
|
2020-07-28 23:09:34 +05:30
|
|
|
delete ':id/packages/:package_id' do
|
|
|
|
authorize_destroy_package!(user_project)
|
|
|
|
|
|
|
|
package = ::Packages::PackageFinder
|
|
|
|
.new(user_project, params[:package_id]).execute
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
destroy_conditionally!(package) do |package|
|
2022-03-02 08:16:31 +05:30
|
|
|
::Packages::MarkPackageForDestructionService.new(container: package, current_user: current_user).execute
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|