debian-mirror-gitlab/lib/api/project_export.rb

76 lines
2.4 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-03-27 19:54:05 +05:30
module API
2021-01-03 14:25:43 +05:30
class ProjectExport < ::API::Base
2020-04-22 19:07:51 +05:30
helpers Helpers::RateLimiter
2020-01-01 13:55:28 +05:30
2021-01-29 00:20:46 +05:30
feature_category :importers
2018-03-27 19:54:05 +05:30
before do
not_found! unless Gitlab::CurrentSettings.project_export_enabled?
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
detail 'This feature was introduced in GitLab 10.6.'
success Entities::ProjectExportStatus
end
get ':id/export' do
present user_project, with: Entities::ProjectExportStatus
end
desc 'Download export' do
detail 'This feature was introduced in GitLab 10.6.'
end
get ':id/export/download' do
2020-06-23 00:09:42 +05:30
check_rate_limit! :project_download_export, [current_user, user_project]
2020-01-01 13:55:28 +05:30
2018-11-20 20:47:30 +05:30
if user_project.export_file_exists?
present_carrierwave_file!(user_project.export_file)
2018-11-08 19:23:39 +05:30
else
render_api_error!('404 Not found or has expired', 404)
end
2018-03-27 19:54:05 +05:30
end
desc 'Start export' do
detail 'This feature was introduced in GitLab 10.6.'
end
2018-05-09 12:01:36 +05:30
params do
optional :description, type: String, desc: 'Override the project description'
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
end
2018-03-27 19:54:05 +05:30
post ':id/export' do
2020-06-23 00:09:42 +05:30
check_rate_limit! :project_export, [current_user]
2020-01-01 13:55:28 +05:30
2020-10-24 23:57:45 +05:30
user_project.remove_exports
2018-05-09 12:01:36 +05:30
project_export_params = declared_params(include_missing: false)
after_export_params = project_export_params.delete(:upload) || {}
export_strategy = if after_export_params[:url].present?
params = after_export_params.slice(:url, :http_method).symbolize_keys
2021-01-03 14:25:43 +05:30
Gitlab::ImportExport::AfterExportStrategies::WebUploadStrategy.new(**params)
2018-05-09 12:01:36 +05:30
end
if export_strategy&.invalid?
render_validation_error!(export_strategy)
else
user_project.add_export_job(current_user: current_user,
after_export_strategy: export_strategy,
params: project_export_params)
end
2018-03-27 19:54:05 +05:30
accepted!
end
end
end
end