2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2021-01-03 14:25:43 +05:30
|
|
|
class RemoteMirrors < ::API::Base
|
2020-01-01 13:55:28 +05:30
|
|
|
include PaginationParams
|
2023-03-17 16:20:25 +05:30
|
|
|
helpers Helpers::RemoteMirrorsHelpers
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
feature_category :source_code_management
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
before do
|
2020-03-13 15:44:24 +05:30
|
|
|
unauthorized! unless can?(current_user, :admin_remote_mirror, user_project)
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project'
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
|
|
|
desc "List the project's remote mirrors" do
|
2023-01-13 00:05:48 +05:30
|
|
|
success code: 200, model: Entities::RemoteMirror
|
|
|
|
is_array true
|
|
|
|
failure [
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags %w[remote_mirrors]
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
params do
|
|
|
|
use :pagination
|
|
|
|
end
|
|
|
|
get ':id/remote_mirrors' do
|
|
|
|
present paginate(user_project.remote_mirrors),
|
|
|
|
with: Entities::RemoteMirror
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
desc 'Get a single remote mirror' do
|
2023-01-13 00:05:48 +05:30
|
|
|
success code: 200, model: Entities::RemoteMirror
|
|
|
|
failure [
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags %w[remote_mirrors]
|
2022-06-21 17:19:12 +05:30
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :mirror_id, type: String, desc: 'The ID of a remote mirror'
|
|
|
|
end
|
|
|
|
get ':id/remote_mirrors/:mirror_id' do
|
|
|
|
mirror = user_project.remote_mirrors.find(params[:mirror_id])
|
|
|
|
|
|
|
|
present mirror, with: Entities::RemoteMirror
|
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
desc 'Create remote mirror for a project' do
|
2023-01-13 00:05:48 +05:30
|
|
|
success code: 201, model: Entities::RemoteMirror
|
|
|
|
failure [
|
|
|
|
{ code: 400, message: 'Bad request' },
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags %w[remote_mirrors]
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
requires :url, type: String, desc: 'The URL for a remote mirror', documentation: { example: 'https://*****:*****@example.com/gitlab/example.git' }
|
|
|
|
optional :enabled, type: Boolean, desc: 'Determines if the mirror is enabled', documentation: { example: false }
|
|
|
|
optional :keep_divergent_refs, type: Boolean, desc: 'Determines if divergent refs are kept on the target',
|
|
|
|
documentation: { example: false }
|
2023-03-17 16:20:25 +05:30
|
|
|
use :mirror_branches_setting
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
post ':id/remote_mirrors' do
|
|
|
|
create_params = declared_params(include_missing: false)
|
2023-03-17 16:20:25 +05:30
|
|
|
verify_mirror_branches_setting(create_params, user_project)
|
2020-04-08 14:13:33 +05:30
|
|
|
new_mirror = user_project.remote_mirrors.create(create_params)
|
|
|
|
|
|
|
|
if new_mirror.persisted?
|
|
|
|
present new_mirror, with: Entities::RemoteMirror
|
|
|
|
else
|
|
|
|
render_validation_error!(new_mirror)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
desc 'Update the attributes of a single remote mirror' do
|
2023-01-13 00:05:48 +05:30
|
|
|
success code: 200, model: Entities::RemoteMirror
|
|
|
|
failure [
|
|
|
|
{ code: 400, message: 'Bad request' },
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags %w[remote_mirrors]
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :mirror_id, type: String, desc: 'The ID of a remote mirror'
|
2023-01-13 00:05:48 +05:30
|
|
|
optional :enabled, type: Boolean, desc: 'Determines if the mirror is enabled', documentation: { example: true }
|
|
|
|
optional :keep_divergent_refs, type: Boolean, desc: 'Determines if divergent refs are kept on the target',
|
|
|
|
documentation: { example: false }
|
2023-03-17 16:20:25 +05:30
|
|
|
use :mirror_branches_setting
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
put ':id/remote_mirrors/:mirror_id' do
|
|
|
|
mirror = user_project.remote_mirrors.find(params[:mirror_id])
|
|
|
|
|
|
|
|
mirror_params = declared_params(include_missing: false)
|
|
|
|
mirror_params[:id] = mirror_params.delete(:mirror_id)
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
verify_mirror_branches_setting(mirror_params, user_project)
|
2020-03-13 15:44:24 +05:30
|
|
|
update_params = { remote_mirrors_attributes: mirror_params }
|
|
|
|
|
|
|
|
result = ::Projects::UpdateService
|
|
|
|
.new(user_project, current_user, update_params)
|
|
|
|
.execute
|
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
present mirror.reset, with: Entities::RemoteMirror
|
|
|
|
else
|
|
|
|
render_api_error!(result[:message], result[:http_status])
|
|
|
|
end
|
|
|
|
end
|
2022-06-21 17:19:12 +05:30
|
|
|
|
|
|
|
desc 'Delete a single remote mirror' do
|
|
|
|
detail 'This feature was introduced in GitLab 14.10'
|
2023-01-13 00:05:48 +05:30
|
|
|
success code: 204
|
|
|
|
failure [
|
|
|
|
{ code: 400, message: 'Bad request' },
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags %w[remote_mirrors]
|
2022-06-21 17:19:12 +05:30
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :mirror_id, type: String, desc: 'The ID of a remote mirror'
|
|
|
|
end
|
|
|
|
delete ':id/remote_mirrors/:mirror_id' do
|
|
|
|
mirror = user_project.remote_mirrors.find(params[:mirror_id])
|
|
|
|
|
|
|
|
destroy_conditionally!(mirror) do
|
|
|
|
mirror_params = declared_params(include_missing: false).merge(_destroy: 1)
|
|
|
|
mirror_params[:id] = mirror_params.delete(:mirror_id)
|
|
|
|
update_params = { remote_mirrors_attributes: mirror_params }
|
|
|
|
|
|
|
|
# Note: We are using the update service to be consistent with how the controller handles deletion
|
|
|
|
result = ::Projects::UpdateService.new(user_project, current_user, update_params).execute
|
|
|
|
|
|
|
|
if result[:status] != :success
|
|
|
|
render_api_error!(result[:message], 400)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|