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

132 lines
5.3 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
module API
module Concerns
module Packages
2021-09-04 01:27:46 +05:30
module DebianPackageEndpoints
2021-06-08 01:23:25 +05:30
extend ActiveSupport::Concern
DISTRIBUTION_REQUIREMENTS = {
2021-09-30 23:02:18 +05:30
distribution: ::Packages::Debian::DISTRIBUTION_REGEX
2021-06-08 01:23:25 +05:30
}.freeze
COMPONENT_ARCHITECTURE_REQUIREMENTS = {
2021-09-30 23:02:18 +05:30
component: ::Packages::Debian::COMPONENT_REGEX,
architecture: ::Packages::Debian::ARCHITECTURE_REGEX
2021-06-08 01:23:25 +05:30
}.freeze
included do
feature_category :package_registry
helpers ::API::Helpers::PackagesHelpers
helpers ::API::Helpers::Packages::BasicAuthHelpers
2021-09-04 01:27:46 +05:30
include ::API::Helpers::Authentication
2021-06-08 01:23:25 +05:30
2021-10-27 15:23:28 +05:30
helpers do
params :shared_package_file_params do
requires :distribution, type: String, desc: 'The Debian Codename or Suite', regexp: Gitlab::Regex.debian_distribution_regex
requires :letter, type: String, desc: 'The Debian Classification (first-letter or lib-first-letter)'
requires :package_name, type: String, desc: 'The Debian Source Package Name', regexp: Gitlab::Regex.debian_package_name_regex
requires :package_version, type: String, desc: 'The Debian Source Package Version', regexp: Gitlab::Regex.debian_version_regex
requires :file_name, type: String, desc: 'The Debian File Name'
2021-09-04 01:27:46 +05:30
end
2021-06-08 01:23:25 +05:30
2021-10-27 15:23:28 +05:30
def distribution_from!(container)
::Packages::Debian::DistributionsFinder.new(container, codename_or_suite: params[:distribution]).execute.last!
2021-09-30 23:02:18 +05:30
end
2021-10-27 15:23:28 +05:30
def present_package_file!
not_found! unless params[:package_name].start_with?(params[:letter])
2021-06-08 01:23:25 +05:30
2021-10-27 15:23:28 +05:30
package_file = distribution_from!(user_project).package_files.with_file_name(params[:file_name]).last!
present_carrierwave_file!(package_file.file)
2021-06-08 01:23:25 +05:30
end
2021-10-27 15:23:28 +05:30
end
2021-06-08 01:23:25 +05:30
2021-10-27 15:23:28 +05:30
rescue_from ArgumentError do |e|
render_api_error!(e.message, 400)
end
2021-06-08 01:23:25 +05:30
2021-10-27 15:23:28 +05:30
rescue_from ActiveRecord::RecordInvalid do |e|
render_api_error!(e.message, 400)
end
2021-06-08 01:23:25 +05:30
2021-12-11 22:18:48 +05:30
authenticate_with do |accept|
accept.token_types(:personal_access_token, :deploy_token, :job_token)
.sent_through(:http_basic_auth)
end
2021-10-27 15:23:28 +05:30
format :txt
content_type :txt, 'text/plain'
2021-06-08 01:23:25 +05:30
2021-10-27 15:23:28 +05:30
params do
requires :distribution, type: String, desc: 'The Debian Codename or Suite', regexp: Gitlab::Regex.debian_distribution_regex
end
2021-06-08 01:23:25 +05:30
2021-10-27 15:23:28 +05:30
namespace 'dists/*distribution', requirements: DISTRIBUTION_REQUIREMENTS do
# GET {projects|groups}/:id/packages/debian/dists/*distribution/Release.gpg
desc 'The Release file signature' do
detail 'This feature was introduced in GitLab 13.5'
end
2021-06-08 01:23:25 +05:30
2021-10-27 15:23:28 +05:30
route_setting :authentication, authenticate_non_public: true
get 'Release.gpg' do
distribution_from!(project_or_group).file_signature
end
2021-06-08 01:23:25 +05:30
2021-10-27 15:23:28 +05:30
# GET {projects|groups}/:id/packages/debian/dists/*distribution/Release
desc 'The unsigned Release file' do
detail 'This feature was introduced in GitLab 13.5'
end
route_setting :authentication, authenticate_non_public: true
get 'Release' do
present_carrierwave_file!(distribution_from!(project_or_group).file)
end
# GET {projects|groups}/:id/packages/debian/dists/*distribution/InRelease
desc 'The signed Release file' do
detail 'This feature was introduced in GitLab 13.5'
end
route_setting :authentication, authenticate_non_public: true
get 'InRelease' do
present_carrierwave_file!(distribution_from!(project_or_group).signed_file)
2021-06-08 01:23:25 +05:30
end
params do
requires :component, type: String, desc: 'The Debian Component', regexp: Gitlab::Regex.debian_component_regex
2021-10-27 15:23:28 +05:30
requires :architecture, type: String, desc: 'The Debian Architecture', regexp: Gitlab::Regex.debian_architecture_regex
2021-06-08 01:23:25 +05:30
end
2021-10-27 15:23:28 +05:30
namespace ':component/binary-:architecture', requirements: COMPONENT_ARCHITECTURE_REQUIREMENTS do
# GET {projects|groups}/:id/packages/debian/dists/*distribution/:component/binary-:architecture/Packages
desc 'The binary files index' do
2021-06-08 01:23:25 +05:30
detail 'This feature was introduced in GitLab 13.5'
end
2021-09-04 01:27:46 +05:30
route_setting :authentication, authenticate_non_public: true
2021-10-27 15:23:28 +05:30
get 'Packages' do
relation = "::Packages::Debian::#{project_or_group.class.name}ComponentFile".constantize
component_file = relation
.preload_distribution
.with_container(project_or_group)
.with_codename_or_suite(params[:distribution])
.with_component_name(params[:component])
.with_file_type(:packages)
.with_architecture_name(params[:architecture])
.with_compression_type(nil)
.order_created_asc
.last!
present_carrierwave_file!(component_file.file)
2021-06-08 01:23:25 +05:30
end
end
end
end
end
end
end
end