debian-mirror-gitlab/lib/api/concerns/packages/debian_distribution_endpoints.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

229 lines
10 KiB
Ruby
Raw Normal View History

2021-09-04 01:27:46 +05:30
# frozen_string_literal: true
module API
module Concerns
module Packages
module DebianDistributionEndpoints
extend ActiveSupport::Concern
included do
include PaginationParams
feature_category :package_registry
2022-07-16 23:28:13 +05:30
urgency :low
2021-09-04 01:27:46 +05:30
helpers ::API::Helpers::PackagesHelpers
helpers ::API::Helpers::Packages::BasicAuthHelpers
include ::API::Helpers::Authentication
2021-12-11 22:18:48 +05:30
helpers do
def distribution
::Packages::Debian::DistributionsFinder.new(project_or_group, codename: params[:codename]).execute.last || not_found!('Distribution')
end
end
2021-09-04 01:27:46 +05:30
namespace 'debian_distributions' do
helpers do
params :optional_distribution_params do
2023-03-04 22:38:38 +05:30
optional :suite, type: String, regexp: Gitlab::Regex.debian_distribution_regex, desc: 'The Debian Suite', documentation: { example: 'unstable' }
optional :origin, type: String, regexp: Gitlab::Regex.debian_distribution_regex, desc: 'The Debian Origin', documentation: { example: 'Grep' }
optional :label, type: String, regexp: Gitlab::Regex.debian_distribution_regex, desc: 'The Debian Label', documentation: { example: 'grep.be' }
optional :version, type: String, regexp: Gitlab::Regex.debian_version_regex, desc: 'The Debian Version', documentation: { example: '12' }
optional :description, type: String, desc: 'The Debian Description', documentation: { example: 'My description' }
optional :valid_time_duration_seconds, type: Integer, desc: 'The duration before the Release file should be considered expired by the client', documentation: { example: 604800 }
2021-09-04 01:27:46 +05:30
optional :components, type: Array[String],
2022-08-27 11:52:29 +05:30
coerce_with: ::API::Validations::Types::CommaSeparatedToArray.coerce,
regexp: Gitlab::Regex.debian_component_regex,
2023-03-04 22:38:38 +05:30
desc: 'The list of Components',
documentation: { example: 'main' }
2021-09-04 01:27:46 +05:30
optional :architectures, type: Array[String],
2022-08-27 11:52:29 +05:30
coerce_with: ::API::Validations::Types::CommaSeparatedToArray.coerce,
regexp: Gitlab::Regex.debian_architecture_regex,
2023-03-04 22:38:38 +05:30
desc: 'The list of Architectures',
documentation: { example: 'amd64' }
2021-09-04 01:27:46 +05:30
end
end
2021-12-11 22:18:48 +05:30
rescue_from ArgumentError do |e|
render_api_error!(e.message, 400)
end
rescue_from ActiveRecord::RecordInvalid do |e|
render_api_error!(e.message, 400)
end
2021-09-04 01:27:46 +05:30
authenticate_with do |accept|
2021-12-11 22:18:48 +05:30
accept.token_types(:personal_access_token).sent_through(:http_private_token_header)
accept.token_types(:deploy_token).sent_through(:http_deploy_token_header)
accept.token_types(:job_token).sent_through(:http_job_token_header)
2021-09-04 01:27:46 +05:30
end
content_type :json, 'application/json'
format :json
# POST {projects|groups}/:id/debian_distributions
desc 'Create a Debian Distribution' do
detail 'This feature was introduced in 14.0'
2023-03-04 22:38:38 +05:30
success code: 201, model: ::API::Entities::Packages::Debian::Distribution
failure [
{ code: 400, message: 'Bad Request' },
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[debian_distribution]
2021-09-04 01:27:46 +05:30
end
params do
2023-03-04 22:38:38 +05:30
requires :codename, type: String, regexp: Gitlab::Regex.debian_distribution_regex, desc: 'The Debian Codename', documentation: { example: 'unstable' }
2021-09-04 01:27:46 +05:30
use :optional_distribution_params
end
post '/' do
authorize_create_package!(project_or_group)
distribution_params = declared_params(include_missing: false)
result = ::Packages::Debian::CreateDistributionService.new(project_or_group, current_user, distribution_params).execute
2021-12-11 22:18:48 +05:30
created_distribution = result.payload[:distribution]
2021-09-04 01:27:46 +05:30
if result.success?
2021-12-11 22:18:48 +05:30
present created_distribution, with: ::API::Entities::Packages::Debian::Distribution
2021-09-04 01:27:46 +05:30
else
2021-12-11 22:18:48 +05:30
render_validation_error!(created_distribution)
2021-09-04 01:27:46 +05:30
end
end
# GET {projects|groups}/:id/debian_distributions
desc 'Get a list of Debian Distributions' do
detail 'This feature was introduced in 14.0'
2023-03-04 22:38:38 +05:30
success code: 200, model: ::API::Entities::Packages::Debian::Distribution
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[debian_distribution]
2021-09-04 01:27:46 +05:30
end
params do
use :pagination
2023-03-04 22:38:38 +05:30
optional :codename, type: String, regexp: Gitlab::Regex.debian_distribution_regex, desc: 'The Debian Codename', documentation: { example: 'unstable' }
2021-09-04 01:27:46 +05:30
use :optional_distribution_params
end
get '/' do
2021-10-27 15:23:28 +05:30
authorize_read_package!(project_or_group)
2021-09-04 01:27:46 +05:30
distribution_params = declared_params(include_missing: false)
distributions = ::Packages::Debian::DistributionsFinder.new(project_or_group, distribution_params).execute
present paginate(distributions), with: ::API::Entities::Packages::Debian::Distribution
end
# GET {projects|groups}/:id/debian_distributions/:codename
desc 'Get a Debian Distribution' do
detail 'This feature was introduced in 14.0'
2023-03-04 22:38:38 +05:30
success code: 200, model: ::API::Entities::Packages::Debian::Distribution
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[debian_distribution]
2021-09-04 01:27:46 +05:30
end
params do
2023-03-04 22:38:38 +05:30
requires :codename, type: String, regexp: Gitlab::Regex.debian_distribution_regex, desc: 'The Debian Codename', documentation: { example: 'unstable' }
2021-09-04 01:27:46 +05:30
end
get '/:codename' do
2021-10-27 15:23:28 +05:30
authorize_read_package!(project_or_group)
2021-09-04 01:27:46 +05:30
present distribution, with: ::API::Entities::Packages::Debian::Distribution
end
2021-12-11 22:18:48 +05:30
# GET {projects|groups}/:id/debian_distributions/:codename/key
desc 'Get a Debian Distribution Key' do
detail 'This feature was introduced in 14.4'
2023-03-04 22:38:38 +05:30
success code: 200, model: ::API::Entities::Packages::Debian::Distribution
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[debian_distribution]
2021-12-11 22:18:48 +05:30
end
params do
2023-03-04 22:38:38 +05:30
requires :codename, type: String, regexp: Gitlab::Regex.debian_distribution_regex, desc: 'The Debian Codename', documentation: { example: 'unstable' }
2021-12-11 22:18:48 +05:30
end
get '/:codename/key.asc' do
authorize_read_package!(project_or_group)
content_type 'text/plain'
env['api.format'] = :binary
header 'Content-Disposition', "attachment; filename*=UTF-8''#{CGI.escape(params[:codename])}.asc"
distribution.key&.public_key || not_found!('Distribution key')
end
2021-09-04 01:27:46 +05:30
# PUT {projects|groups}/:id/debian_distributions/:codename
desc 'Update a Debian Distribution' do
detail 'This feature was introduced in 14.0'
2023-03-04 22:38:38 +05:30
success code: 200, model: ::API::Entities::Packages::Debian::Distribution
failure [
{ code: 400, message: 'Bad Request' },
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[debian_distribution]
2021-09-04 01:27:46 +05:30
end
params do
2023-03-04 22:38:38 +05:30
requires :codename, type: String, regexp: Gitlab::Regex.debian_distribution_regex, desc: 'The Debian Codename', documentation: { example: 'unstable' }
2021-09-04 01:27:46 +05:30
use :optional_distribution_params
end
put '/:codename' do
authorize_create_package!(project_or_group)
distribution_params = declared_params(include_missing: false).except(:codename)
result = ::Packages::Debian::UpdateDistributionService.new(distribution, distribution_params).execute
2021-12-11 22:18:48 +05:30
updated_distribution = result.payload[:distribution]
2021-09-04 01:27:46 +05:30
if result.success?
2021-12-11 22:18:48 +05:30
present updated_distribution, with: ::API::Entities::Packages::Debian::Distribution
2021-09-04 01:27:46 +05:30
else
2021-12-11 22:18:48 +05:30
render_validation_error!(updated_distribution)
2021-09-04 01:27:46 +05:30
end
end
# DELETE {projects|groups}/:id/debian_distributions/:codename
desc 'Delete a Debian Distribution' do
detail 'This feature was introduced in 14.0'
2023-03-04 22:38:38 +05:30
success code: 202
failure [
{ code: 400, message: 'Bad Request' },
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[debian_distribution]
2021-09-04 01:27:46 +05:30
end
params do
2023-03-04 22:38:38 +05:30
requires :codename, type: String, regexp: Gitlab::Regex.debian_distribution_regex, desc: 'The Debian Codename', documentation: { example: 'unstable' }
2021-09-04 01:27:46 +05:30
use :optional_distribution_params
end
delete '/:codename' do
authorize_destroy_package!(project_or_group)
accepted! if distribution.destroy
render_api_error!('Failed to delete distribution', 400)
end
end
end
end
end
end
end