2018-09-29 18:34:47 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-02 14:49:01 -05:00
|
|
|
module API
|
2020-10-14 20:08:42 -04:00
|
|
|
class ProjectExport < ::API::Base
|
2020-10-30 11:08:59 -04:00
|
|
|
feature_category :importers
|
2022-04-27 14:10:15 -04:00
|
|
|
urgency :low
|
2020-10-30 11:08:59 -04:00
|
|
|
|
2017-12-02 14:49:01 -05:00
|
|
|
before do
|
2018-02-28 22:32:03 -05:00
|
|
|
not_found! unless Gitlab::CurrentSettings.project_export_enabled?
|
2017-12-02 14:49:01 -05:00
|
|
|
authorize_admin_project
|
|
|
|
end
|
|
|
|
|
|
|
|
params do
|
|
|
|
requires :id, type: String, desc: 'The ID of a project'
|
|
|
|
end
|
|
|
|
resource :projects, requirements: { id: %r{[^/]+} } do
|
|
|
|
desc 'Get export status' do
|
2018-02-24 22:18:46 -05:00
|
|
|
detail 'This feature was introduced in GitLab 10.6.'
|
2017-12-02 14:49:01 -05:00
|
|
|
success Entities::ProjectExportStatus
|
|
|
|
end
|
|
|
|
get ':id/export' do
|
|
|
|
present user_project, with: Entities::ProjectExportStatus
|
|
|
|
end
|
|
|
|
|
2018-02-24 22:18:46 -05:00
|
|
|
desc 'Download export' do
|
|
|
|
detail 'This feature was introduced in GitLab 10.6.'
|
|
|
|
end
|
2017-12-02 14:49:01 -05:00
|
|
|
get ':id/export/download' do
|
2022-04-14 14:08:29 -04:00
|
|
|
check_rate_limit! :project_download_export, scope: [current_user, user_project.namespace]
|
2019-12-05 16:07:40 -05:00
|
|
|
|
2018-09-07 08:43:51 -04:00
|
|
|
if user_project.export_file_exists?
|
2021-06-15 02:10:17 -04:00
|
|
|
if user_project.export_archive_exists?
|
|
|
|
present_carrierwave_file!(user_project.export_file)
|
|
|
|
else
|
|
|
|
render_api_error!('The project export file is not available yet', 404)
|
|
|
|
end
|
2018-06-25 09:10:26 -04:00
|
|
|
else
|
|
|
|
render_api_error!('404 Not found or has expired', 404)
|
|
|
|
end
|
2017-12-02 14:49:01 -05:00
|
|
|
end
|
|
|
|
|
2018-02-24 22:18:46 -05:00
|
|
|
desc 'Start export' do
|
|
|
|
detail 'This feature was introduced in GitLab 10.6.'
|
|
|
|
end
|
2018-03-14 10:17:35 -04:00
|
|
|
params do
|
|
|
|
optional :description, type: String, desc: 'Override the project description'
|
2018-03-30 11:45:59 -04:00
|
|
|
optional :upload, type: Hash do
|
|
|
|
optional :url, type: String, desc: 'The URL to upload the project'
|
|
|
|
optional :http_method, type: String, default: 'PUT', desc: 'HTTP method to upload the exported project'
|
|
|
|
end
|
2018-03-14 10:17:35 -04:00
|
|
|
end
|
2017-12-02 14:49:01 -05:00
|
|
|
post ':id/export' do
|
2021-12-10 10:10:24 -05:00
|
|
|
check_rate_limit! :project_export, scope: current_user
|
2019-12-05 16:07:40 -05:00
|
|
|
|
2020-07-21 20:09:26 -04:00
|
|
|
user_project.remove_exports
|
|
|
|
|
2018-03-14 10:17:35 -04:00
|
|
|
project_export_params = declared_params(include_missing: false)
|
2018-03-30 11:45:59 -04:00
|
|
|
after_export_params = project_export_params.delete(:upload) || {}
|
2018-03-14 10:17:35 -04:00
|
|
|
|
2018-03-30 11:45:59 -04:00
|
|
|
export_strategy = if after_export_params[:url].present?
|
|
|
|
params = after_export_params.slice(:url, :http_method).symbolize_keys
|
|
|
|
|
2020-09-30 17:10:09 -04:00
|
|
|
Gitlab::ImportExport::AfterExportStrategies::WebUploadStrategy.new(**params)
|
2018-03-30 11:45:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if export_strategy&.invalid?
|
|
|
|
render_validation_error!(export_strategy)
|
|
|
|
else
|
2022-05-11 14:07:55 -04:00
|
|
|
begin
|
|
|
|
user_project.add_export_job(current_user: current_user,
|
|
|
|
after_export_strategy: export_strategy,
|
|
|
|
params: project_export_params)
|
|
|
|
rescue Project::ExportLimitExceeded => e
|
|
|
|
render_api_error!(e.message, 400)
|
|
|
|
end
|
2018-03-30 11:45:59 -04:00
|
|
|
end
|
2017-12-02 14:49:01 -05:00
|
|
|
|
|
|
|
accepted!
|
|
|
|
end
|
2021-09-21 20:09:28 -04:00
|
|
|
|
|
|
|
resource do
|
|
|
|
before do
|
2022-05-06 11:09:03 -04:00
|
|
|
not_found! unless ::Feature.enabled?(:bulk_import)
|
2021-09-21 20:09:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Start relations export' do
|
|
|
|
detail 'This feature was introduced in GitLab 14.4'
|
|
|
|
end
|
|
|
|
post ':id/export_relations' do
|
|
|
|
response = ::BulkImports::ExportService.new(portable: user_project, user: current_user).execute
|
|
|
|
|
|
|
|
if response.success?
|
|
|
|
accepted!
|
|
|
|
else
|
|
|
|
render_api_error!(message: 'Project relations export could not be started.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Download relations export' do
|
|
|
|
detail 'This feature was introduced in GitLab 14.4'
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :relation,
|
|
|
|
type: String,
|
|
|
|
project_portable: true,
|
|
|
|
desc: 'Project relation name'
|
|
|
|
end
|
|
|
|
get ':id/export_relations/download' do
|
|
|
|
export = user_project.bulk_import_exports.find_by_relation(params[:relation])
|
|
|
|
file = export&.upload&.export_file
|
|
|
|
|
|
|
|
if file
|
|
|
|
present_carrierwave_file!(file)
|
|
|
|
else
|
|
|
|
render_api_error!('404 Not found', 404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Relations export status' do
|
|
|
|
detail 'This feature was introduced in GitLab 14.4'
|
|
|
|
end
|
|
|
|
get ':id/export_relations/status' do
|
|
|
|
present user_project.bulk_import_exports, with: Entities::BulkImports::ExportStatus
|
|
|
|
end
|
|
|
|
end
|
2017-12-02 14:49:01 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|