2020-07-17 02:09:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2020-10-14 20:08:42 -04:00
|
|
|
class ProjectPackages < ::API::Base
|
2020-07-17 02:09:11 -04:00
|
|
|
include PaginationParams
|
|
|
|
|
|
|
|
before do
|
|
|
|
authorize_packages_access!(user_project)
|
|
|
|
end
|
|
|
|
|
2020-10-30 11:08:59 -04:00
|
|
|
feature_category :package_registry
|
|
|
|
|
2020-07-17 02:09:11 -04:00
|
|
|
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-01-06 16:10:18 -05:00
|
|
|
optional :include_versionless, type: Boolean,
|
|
|
|
desc: 'Returns packages without a version'
|
2020-07-17 02:09:11 -04:00
|
|
|
end
|
|
|
|
get ':id/packages' do
|
|
|
|
packages = ::Packages::PackagesFinder.new(
|
|
|
|
user_project,
|
2021-01-06 16:10:18 -05:00
|
|
|
declared_params.slice(:order_by, :sort, :package_type, :package_name, :include_versionless)
|
2020-07-17 02:09:11 -04:00
|
|
|
).execute
|
|
|
|
|
|
|
|
present paginate(packages), with: ::API::Entities::Package, user: current_user
|
|
|
|
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
|
|
|
|
get ':id/packages/:package_id' do
|
|
|
|
package = ::Packages::PackageFinder
|
|
|
|
.new(user_project, params[:package_id]).execute
|
|
|
|
|
|
|
|
present package, with: ::API::Entities::Package, user: current_user
|
|
|
|
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
|
|
|
|
delete ':id/packages/:package_id' do
|
|
|
|
authorize_destroy_package!(user_project)
|
|
|
|
|
|
|
|
package = ::Packages::PackageFinder
|
|
|
|
.new(user_project, params[:package_id]).execute
|
|
|
|
|
|
|
|
destroy_conditionally!(package)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|