debian-mirror-gitlab/lib/api/release/links.rb

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

177 lines
6.8 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module API
module Release
2021-01-03 14:25:43 +05:30
class Links < ::API::Base
2019-02-15 15:39:39 +05:30
include PaginationParams
2023-01-13 00:05:48 +05:30
release_links_tags = %w[release_links]
2019-12-04 20:38:33 +05:30
RELEASE_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS
2019-02-15 15:39:39 +05:30
.merge(tag_name: API::NO_SLASH_URL_PART_REGEX)
2023-03-04 22:38:38 +05:30
after_validation { authorize! :read_release, user_project }
2019-03-13 22:55:13 +05:30
2021-01-29 00:20:46 +05:30
feature_category :release_orchestration
2022-07-16 23:28:13 +05:30
urgency :low
2021-01-29 00:20:46 +05:30
2019-02-15 15:39:39 +05:30
params do
2023-03-04 22:38:38 +05:30
requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project'
2019-02-15 15:39:39 +05:30
end
resource 'projects/:id', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
params do
2023-01-13 00:05:48 +05:30
requires :tag_name, type: String, desc: 'The tag associated with the release', as: :tag
2019-02-15 15:39:39 +05:30
end
2019-12-04 20:38:33 +05:30
resource 'releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMENTS do
2019-02-15 15:39:39 +05:30
resource :assets do
2023-01-13 00:05:48 +05:30
desc 'List links of a release' do
detail 'Get assets as links from a release. This feature was introduced in GitLab 11.7.'
2019-02-15 15:39:39 +05:30
success Entities::Releases::Link
2023-01-13 00:05:48 +05:30
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not found' }
]
is_array true
tags release_links_tags
2019-02-15 15:39:39 +05:30
end
params do
use :pagination
end
2022-07-23 23:45:48 +05:30
route_setting :authentication, job_token_allowed: true
2019-02-15 15:39:39 +05:30
get 'links' do
authorize! :read_release, release
present paginate(release.links.sorted), with: Entities::Releases::Link
end
2023-01-13 00:05:48 +05:30
desc 'Create a release link' do
detail 'Create an asset as a link from a release. This feature was introduced in GitLab 11.7.'
2019-02-15 15:39:39 +05:30
success Entities::Releases::Link
2023-01-13 00:05:48 +05:30
failure [
{ code: 400, message: 'Bad request' },
{ code: 401, message: 'Unauthorized' }
]
tags release_links_tags
2019-02-15 15:39:39 +05:30
end
params do
2023-01-13 00:05:48 +05:30
requires :name, type: String, desc: 'The name of the link. Link names must be unique in the release'
requires :url, type: String, desc: 'The URL of the link. Link URLs must be unique in the release.'
2023-03-17 16:20:25 +05:30
optional :direct_asset_path, type: String, desc: 'Optional path for a direct asset link', as: :filepath
2023-01-13 00:05:48 +05:30
optional :link_type,
type: String,
values: %w[other runbook image package],
default: 'other',
desc: 'The type of the link: `other`, `runbook`, `image`, or `package`. Defaults to `other`'
2019-02-15 15:39:39 +05:30
end
2022-07-23 23:45:48 +05:30
route_setting :authentication, job_token_allowed: true
2019-02-15 15:39:39 +05:30
post 'links' do
2023-05-27 22:25:52 +05:30
result = ::Releases::Links::CreateService
.new(release, current_user, declared_params(include_missing: false))
.execute
if result.success?
present result.payload[:link], with: Entities::Releases::Link
elsif result.reason == ::Releases::Links::REASON_FORBIDDEN
forbidden!
2019-02-15 15:39:39 +05:30
else
2023-05-27 22:25:52 +05:30
render_api_error!(result.message, 400)
2019-02-15 15:39:39 +05:30
end
end
params do
2023-01-13 00:05:48 +05:30
requires :link_id, type: Integer, desc: 'The ID of the link'
2019-02-15 15:39:39 +05:30
end
resource 'links/:link_id' do
2023-01-13 00:05:48 +05:30
desc 'Get a release link' do
detail 'Get an asset as a link from a release. This feature was introduced in GitLab 11.7.'
2019-02-15 15:39:39 +05:30
success Entities::Releases::Link
2023-01-13 00:05:48 +05:30
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not found' }
]
tags release_links_tags
2019-02-15 15:39:39 +05:30
end
2022-07-23 23:45:48 +05:30
route_setting :authentication, job_token_allowed: true
2019-02-15 15:39:39 +05:30
get do
authorize! :read_release, release
present link, with: Entities::Releases::Link
end
2023-01-13 00:05:48 +05:30
desc 'Update a release link' do
detail 'Update an asset as a link from a release. This feature was introduced in GitLab 11.7.'
2019-02-15 15:39:39 +05:30
success Entities::Releases::Link
2023-01-13 00:05:48 +05:30
failure [
{ code: 400, message: 'Bad request' },
{ code: 401, message: 'Unauthorized' }
]
tags release_links_tags
2019-02-15 15:39:39 +05:30
end
params do
optional :name, type: String, desc: 'The name of the link'
optional :url, type: String, desc: 'The URL of the link'
2023-03-17 16:20:25 +05:30
optional :direct_asset_path, type: String, desc: 'Optional path for a direct asset link', as: :filepath
2023-01-13 00:05:48 +05:30
optional :link_type,
type: String,
values: %w[other runbook image package],
default: 'other',
desc: 'The type of the link: `other`, `runbook`, `image`, or `package`. Defaults to `other`'
2019-02-15 15:39:39 +05:30
at_least_one_of :name, :url
end
2022-07-23 23:45:48 +05:30
route_setting :authentication, job_token_allowed: true
2019-02-15 15:39:39 +05:30
put do
2023-05-27 22:25:52 +05:30
result = ::Releases::Links::UpdateService
.new(release, current_user, declared_params(include_missing: false))
.execute(link)
if result.success?
present result.payload[:link], with: Entities::Releases::Link
elsif result.reason == ::Releases::Links::REASON_FORBIDDEN
forbidden!
2019-02-15 15:39:39 +05:30
else
2023-05-27 22:25:52 +05:30
render_api_error!(result.message, 400)
2019-02-15 15:39:39 +05:30
end
end
2023-01-13 00:05:48 +05:30
desc 'Delete a release link' do
detail 'Deletes an asset as a link from a release. This feature was introduced in GitLab 11.7.'
2019-02-15 15:39:39 +05:30
success Entities::Releases::Link
2023-01-13 00:05:48 +05:30
failure [
{ code: 400, message: 'Bad request' },
{ code: 401, message: 'Unauthorized' }
]
tags release_links_tags
2019-02-15 15:39:39 +05:30
end
2022-07-23 23:45:48 +05:30
route_setting :authentication, job_token_allowed: true
2019-02-15 15:39:39 +05:30
delete do
2023-05-27 22:25:52 +05:30
result = ::Releases::Links::DestroyService
.new(release, current_user)
.execute(link)
if result.success?
present result.payload[:link], with: Entities::Releases::Link
elsif result.reason == ::Releases::Links::REASON_FORBIDDEN
forbidden!
2019-02-15 15:39:39 +05:30
else
2023-05-27 22:25:52 +05:30
render_api_error!(result.message, 400)
2019-02-15 15:39:39 +05:30
end
end
end
end
end
end
helpers do
def release
@release ||= user_project.releases.find_by_tag!(params[:tag])
end
def link
@link ||= release.links.find(params[:link_id])
end
end
end
end
end