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

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

506 lines
21 KiB
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
# Conan Package Manager Client API
#
# These API endpoints are not consumed directly by users, so there is no documentation for the
# individual endpoints. They are called by the Conan package manager client when users run commands
# like `conan install` or `conan upload`. The usage of the GitLab Conan repository is documented here:
# https://docs.gitlab.com/ee/user/packages/conan_repository/#installing-a-package
#
# Technical debt: https://gitlab.com/gitlab-org/gitlab/issues/35798
module API
module Concerns
module Packages
module ConanEndpoints
extend ActiveSupport::Concern
PACKAGE_REQUIREMENTS = {
package_name: API::NO_SLASH_URL_PART_REGEX,
package_version: API::NO_SLASH_URL_PART_REGEX,
package_username: API::NO_SLASH_URL_PART_REGEX,
package_channel: API::NO_SLASH_URL_PART_REGEX
}.freeze
FILE_NAME_REQUIREMENTS = {
file_name: API::NO_SLASH_URL_PART_REGEX
}.freeze
PACKAGE_COMPONENT_REGEX = Gitlab::Regex.conan_recipe_component_regex
CONAN_REVISION_REGEX = Gitlab::Regex.conan_revision_regex
2022-01-26 12:08:38 +05:30
CONAN_REVISION_USER_CHANNEL_REGEX = Gitlab::Regex.conan_recipe_user_channel_regex
2021-02-22 17:27:13 +05:30
2023-01-13 00:05:48 +05:30
CONAN_FILES = (Gitlab::Regex::Packages::CONAN_RECIPE_FILES + Gitlab::Regex::Packages::CONAN_PACKAGE_FILES).uniq.freeze
2021-02-22 17:27:13 +05:30
included do
feature_category :package_registry
helpers ::API::Helpers::PackagesManagerClientsHelpers
helpers ::API::Helpers::Packages::Conan::ApiHelpers
helpers ::API::Helpers::RelatedResourcesHelpers
2022-05-07 20:08:51 +05:30
rescue_from ActiveRecord::RecordInvalid do |e|
render_api_error!(e.message, 400)
end
2021-02-22 17:27:13 +05:30
before do
2022-08-13 15:12:31 +05:30
not_found! if Gitlab::FIPS.enabled?
2021-02-22 17:27:13 +05:30
require_packages_enabled!
# Personal access token will be extracted from Bearer or Basic authorization
# in the overridden find_personal_access_token or find_user_from_job_token helpers
2021-04-17 20:07:23 +05:30
authenticate_non_get!
2021-02-22 17:27:13 +05:30
end
desc 'Ping the Conan API' do
detail 'This feature was introduced in GitLab 12.2'
2023-03-04 22:38:38 +05:30
success code: 200
failure [
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
get 'ping', urgency: :default do
2021-02-22 17:27:13 +05:30
header 'X-Conan-Server-Capabilities', [].join(',')
end
desc 'Search for packages' do
detail 'This feature was introduced in GitLab 12.4'
2023-03-04 22:38:38 +05:30
success code: 200
failure [
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
params do
2023-03-04 22:38:38 +05:30
requires :q, type: String, desc: 'Search query', documentation: { example: 'Hello*' }
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
get 'conans/search', urgency: :low do
2021-02-22 17:27:13 +05:30
service = ::Packages::Conan::SearchService.new(current_user, query: params[:q]).execute
service.payload
end
namespace 'users' do
2021-04-17 20:07:23 +05:30
before do
authenticate!
end
2021-02-22 17:27:13 +05:30
format :txt
2021-03-11 19:13:27 +05:30
content_type :txt, 'text/plain'
2021-02-22 17:27:13 +05:30
desc 'Authenticate user against conan CLI' do
detail 'This feature was introduced in GitLab 12.2'
2023-03-04 22:38:38 +05:30
success code: 200
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
get 'authenticate', urgency: :low do
2021-02-22 17:27:13 +05:30
unauthorized! unless token
token.to_jwt
end
desc 'Check for valid user credentials per conan CLI' do
detail 'This feature was introduced in GitLab 12.4'
2023-03-04 22:38:38 +05:30
success code: 200
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
get 'check_credentials', urgency: :default do
2021-02-22 17:27:13 +05:30
authenticate!
:ok
end
end
params do
2023-03-04 22:38:38 +05:30
requires :package_name, type: String, regexp: PACKAGE_COMPONENT_REGEX, desc: 'Package name', documentation: { example: 'my-package' }
requires :package_version, type: String, regexp: PACKAGE_COMPONENT_REGEX, desc: 'Package version', documentation: { example: '1.0' }
requires :package_username, type: String, regexp: CONAN_REVISION_USER_CHANNEL_REGEX, desc: 'Package username', documentation: { example: 'my-group+my-project' }
requires :package_channel, type: String, regexp: CONAN_REVISION_USER_CHANNEL_REGEX, desc: 'Package channel', documentation: { example: 'stable' }
2021-02-22 17:27:13 +05:30
end
namespace 'conans/:package_name/:package_version/:package_username/:package_channel', requirements: PACKAGE_REQUIREMENTS do
2022-01-26 12:08:38 +05:30
after_validation do
check_username_channel
end
2021-02-22 17:27:13 +05:30
# Get the snapshot
#
# the snapshot is a hash of { filename: md5 hash }
2023-03-04 22:38:38 +05:30
# md5 hash is the hash of that file. This hash is used to diff the files existing on the client
2021-02-22 17:27:13 +05:30
# to determine which client files need to be uploaded if no recipe exists the snapshot is empty
desc 'Package Snapshot' do
detail 'This feature was introduced in GitLab 12.5'
2023-03-04 22:38:38 +05:30
success code: 200, model: ::API::Entities::ConanPackage::ConanPackageSnapshot
failure [
{ code: 400, message: 'Bad Request' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
params do
2023-03-04 22:38:38 +05:30
requires :conan_package_reference, type: String, desc: 'Conan package ID', documentation: { example: '103f6067a947f366ef91fc1b7da351c588d1827f' }
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
get 'packages/:conan_package_reference', urgency: :low do
2022-10-11 01:57:18 +05:30
authorize_read_package!(project)
2021-02-22 17:27:13 +05:30
presenter = ::Packages::Conan::PackagePresenter.new(
package,
current_user,
project,
conan_package_reference: params[:conan_package_reference]
)
present presenter, with: ::API::Entities::ConanPackage::ConanPackageSnapshot
end
desc 'Recipe Snapshot' do
detail 'This feature was introduced in GitLab 12.5'
2023-03-04 22:38:38 +05:30
success code: 200, model: ::API::Entities::ConanPackage::ConanRecipeSnapshot
failure [
{ code: 400, message: 'Bad Request' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
get urgency: :low do
2022-10-11 01:57:18 +05:30
authorize_read_package!(project)
2021-02-22 17:27:13 +05:30
presenter = ::Packages::Conan::PackagePresenter.new(package, current_user, project)
present presenter, with: ::API::Entities::ConanPackage::ConanRecipeSnapshot
end
# Get the manifest
# returns the download urls for the existing recipe in the registry
#
# the manifest is a hash of { filename: url }
# where the url is the download url for the file
desc 'Package Digest' do
detail 'This feature was introduced in GitLab 12.5'
2023-03-04 22:38:38 +05:30
success code: 200, model: ::API::Entities::ConanPackage::ConanPackageManifest
failure [
{ code: 400, message: 'Bad Request' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
params do
2023-03-04 22:38:38 +05:30
requires :conan_package_reference, type: String, desc: 'Conan package ID', documentation: { example: '103f6067a947f366ef91fc1b7da351c588d1827f' }
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
get 'packages/:conan_package_reference/digest', urgency: :low do
2021-02-22 17:27:13 +05:30
present_package_download_urls
end
desc 'Recipe Digest' do
detail 'This feature was introduced in GitLab 12.5'
2023-03-04 22:38:38 +05:30
success code: 200, model: ::API::Entities::ConanPackage::ConanRecipeManifest
failure [
{ code: 400, message: 'Bad Request' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
get 'digest', urgency: :low do
2021-02-22 17:27:13 +05:30
present_recipe_download_urls
end
# Get the download urls
#
# returns the download urls for the existing recipe or package in the registry
#
# the manifest is a hash of { filename: url }
# where the url is the download url for the file
desc 'Package Download Urls' do
detail 'This feature was introduced in GitLab 12.5'
2023-03-04 22:38:38 +05:30
success code: 200, model: ::API::Entities::ConanPackage::ConanPackageManifest
failure [
{ code: 400, message: 'Bad Request' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
params do
2023-03-04 22:38:38 +05:30
requires :conan_package_reference, type: String, desc: 'Conan package ID', documentation: { example: '103f6067a947f366ef91fc1b7da351c588d1827f' }
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
get 'packages/:conan_package_reference/download_urls', urgency: :low do
2021-02-22 17:27:13 +05:30
present_package_download_urls
end
desc 'Recipe Download Urls' do
detail 'This feature was introduced in GitLab 12.5'
2023-03-04 22:38:38 +05:30
success code: 200, model: ::API::Entities::ConanPackage::ConanRecipeManifest
failure [
{ code: 400, message: 'Bad Request' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
get 'download_urls', urgency: :low do
2021-02-22 17:27:13 +05:30
present_recipe_download_urls
end
# Get the upload urls
#
# request body contains { filename: filesize } where the filename is the
# name of the file the conan client is requesting to upload
#
# returns { filename: url }
# where the url is the upload url for the file that the conan client will use
desc 'Package Upload Urls' do
detail 'This feature was introduced in GitLab 12.4'
2023-03-04 22:38:38 +05:30
success code: 200, model: ::API::Entities::ConanPackage::ConanUploadUrls
failure [
{ code: 400, message: 'Bad Request' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
params do
2023-03-04 22:38:38 +05:30
requires :conan_package_reference, type: String, desc: 'Conan package ID', documentation: { example: '103f6067a947f366ef91fc1b7da351c588d1827f' }
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
post 'packages/:conan_package_reference/upload_urls', urgency: :low do
2022-10-11 01:57:18 +05:30
authorize_read_package!(project)
2021-02-22 17:27:13 +05:30
status 200
present package_upload_urls, with: ::API::Entities::ConanPackage::ConanUploadUrls
end
desc 'Recipe Upload Urls' do
detail 'This feature was introduced in GitLab 12.4'
2023-03-04 22:38:38 +05:30
success code: 200, model: ::API::Entities::ConanPackage::ConanUploadUrls
failure [
{ code: 400, message: 'Bad Request' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
post 'upload_urls', urgency: :low do
2022-10-11 01:57:18 +05:30
authorize_read_package!(project)
2021-02-22 17:27:13 +05:30
status 200
present recipe_upload_urls, with: ::API::Entities::ConanPackage::ConanUploadUrls
end
desc 'Delete Package' do
detail 'This feature was introduced in GitLab 12.5'
2023-03-04 22:38:38 +05:30
success code: 200
failure [
{ code: 400, message: 'Bad Request' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
delete urgency: :low do
2021-02-22 17:27:13 +05:30
authorize!(:destroy_package, project)
2021-09-04 01:27:46 +05:30
track_package_event('delete_package', :conan, category: 'API::ConanPackages', user: current_user, project: project, namespace: project.namespace)
2021-02-22 17:27:13 +05:30
package.destroy
end
end
params do
2023-03-04 22:38:38 +05:30
requires :package_name, type: String, regexp: PACKAGE_COMPONENT_REGEX, desc: 'Package name', documentation: { example: 'my-package' }
requires :package_version, type: String, regexp: PACKAGE_COMPONENT_REGEX, desc: 'Package version', documentation: { example: '1.0' }
requires :package_username, type: String, regexp: CONAN_REVISION_USER_CHANNEL_REGEX, desc: 'Package username', documentation: { example: 'my-group+my-project' }
requires :package_channel, type: String, regexp: CONAN_REVISION_USER_CHANNEL_REGEX, desc: 'Package channel', documentation: { example: 'stable' }
requires :recipe_revision, type: String, regexp: CONAN_REVISION_REGEX, desc: 'Conan Recipe Revision', documentation: { example: '0' }
2021-02-22 17:27:13 +05:30
end
namespace 'files/:package_name/:package_version/:package_username/:package_channel/:recipe_revision', requirements: PACKAGE_REQUIREMENTS do
before do
authenticate_non_get!
end
2022-01-26 12:08:38 +05:30
after_validation do
check_username_channel
end
2021-02-22 17:27:13 +05:30
params do
2023-03-04 22:38:38 +05:30
requires :file_name, type: String, desc: 'Package file name', values: CONAN_FILES, documentation: { example: 'conanfile.py' }
2021-02-22 17:27:13 +05:30
end
2022-05-07 20:08:51 +05:30
2021-02-22 17:27:13 +05:30
namespace 'export/:file_name', requirements: FILE_NAME_REQUIREMENTS do
desc 'Download recipe files' do
detail 'This feature was introduced in GitLab 12.6'
2023-03-04 22:38:38 +05:30
success code: 200
failure [
{ code: 400, message: 'Bad Request' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
get urgency: :low do
2021-02-22 17:27:13 +05:30
download_package_file(:recipe_file)
end
desc 'Upload recipe package files' do
detail 'This feature was introduced in GitLab 12.6'
2023-03-04 22:38:38 +05:30
success code: 200
failure [
{ code: 400, message: 'Bad Request' },
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
params do
2023-01-13 00:05:48 +05:30
requires :file, type: ::API::Validations::Types::WorkhorseFile, desc: 'The package file to be published (generated by Multipart middleware)', documentation: { type: 'file' }
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
put urgency: :low do
2021-02-22 17:27:13 +05:30
upload_package_file(:recipe_file)
end
desc 'Workhorse authorize the conan recipe file' do
detail 'This feature was introduced in GitLab 12.6'
2023-03-04 22:38:38 +05:30
success code: 200
failure [
{ code: 400, message: 'Bad Request' },
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
put 'authorize', urgency: :low do
2021-02-22 17:27:13 +05:30
authorize_workhorse!(subject: project, maximum_size: project.actual_limits.conan_max_file_size)
end
end
params do
2023-03-04 22:38:38 +05:30
requires :conan_package_reference, type: String, desc: 'Conan Package ID', documentation: { example: '103f6067a947f366ef91fc1b7da351c588d1827f' }
requires :package_revision, type: String, desc: 'Conan Package Revision', documentation: { example: '0' }
requires :file_name, type: String, desc: 'Package file name', values: CONAN_FILES, documentation: { example: 'conaninfo.txt' }
2021-02-22 17:27:13 +05:30
end
namespace 'package/:conan_package_reference/:package_revision/:file_name', requirements: FILE_NAME_REQUIREMENTS do
desc 'Download package files' do
detail 'This feature was introduced in GitLab 12.5'
2023-03-04 22:38:38 +05:30
success code: 200
failure [
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
get urgency: :low do
2021-02-22 17:27:13 +05:30
download_package_file(:package_file)
end
desc 'Workhorse authorize the conan package file' do
detail 'This feature was introduced in GitLab 12.6'
2023-03-04 22:38:38 +05:30
success code: 200
failure [
{ code: 400, message: 'Bad Request' },
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
put 'authorize', urgency: :low do
2021-02-22 17:27:13 +05:30
authorize_workhorse!(subject: project, maximum_size: project.actual_limits.conan_max_file_size)
end
desc 'Upload package files' do
detail 'This feature was introduced in GitLab 12.6'
2023-03-04 22:38:38 +05:30
success code: 200
failure [
{ code: 400, message: 'Bad Request' },
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not Found' }
]
tags %w[conan_packages]
2021-02-22 17:27:13 +05:30
end
params do
2023-01-13 00:05:48 +05:30
requires :file, type: ::API::Validations::Types::WorkhorseFile, desc: 'The package file to be published (generated by Multipart middleware)', documentation: { type: 'file' }
2021-02-22 17:27:13 +05:30
end
route_setting :authentication, job_token_allowed: true, basic_auth_personal_access_token: true
2022-07-16 23:28:13 +05:30
put urgency: :low do
2021-02-22 17:27:13 +05:30
upload_package_file(:package_file)
end
end
end
end
end
end
end
end