diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-27 09:09:01 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-27 09:09:01 +0000 |
commit | c72e5ebe9938d315ec598197873e71a80168d40a (patch) | |
tree | 439bf5c40aaf774e5a301825af517cb52726f450 /lib/api/project_import.rb | |
parent | ffc43b862df32a590eae874bcbb11109b46dc8be (diff) | |
download | gitlab-ce-c72e5ebe9938d315ec598197873e71a80168d40a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api/project_import.rb')
-rw-r--r-- | lib/api/project_import.rb | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/lib/api/project_import.rb b/lib/api/project_import.rb index ea793a09f6c..d2247aaee34 100644 --- a/lib/api/project_import.rb +++ b/lib/api/project_import.rb @@ -4,6 +4,8 @@ module API class ProjectImport < Grape::API include PaginationParams + MAXIMUM_FILE_SIZE = 50.megabytes + helpers Helpers::ProjectsHelpers helpers Helpers::FileUploadHelpers @@ -19,6 +21,10 @@ module API def rate_limiter ::Gitlab::ApplicationRateLimiter end + + def with_workhorse_upload_acceleration? + request.headers[Gitlab::Workhorse::INTERNAL_API_REQUEST_HEADER].present? + end end before do @@ -26,10 +32,25 @@ module API end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do + desc 'Workhorse authorize the project import upload' do + detail 'This feature was introduced in GitLab 12.9' + end + post 'import/authorize' do + require_gitlab_workhorse! + + status 200 + content_type Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE + + ImportExportUploader.workhorse_authorize(has_length: false, maximum_size: MAXIMUM_FILE_SIZE) + end + params do requires :path, type: String, desc: 'The new project path and name' # TODO: remove rubocop disable - https://gitlab.com/gitlab-org/gitlab/issues/14960 - requires :file, type: File, desc: 'The project export file to be imported' # rubocop:disable Scalability/FileUploads + # and mark WH fields as required (instead of optional) after the WH version including + # https://gitlab.com/gitlab-org/gitlab-workhorse/-/merge_requests/459 + # is deployed and GITLAB_WORKHORSE_VERSION is updated accordingly. + requires :file, types: [::API::Validations::Types::WorkhorseFile, File], desc: 'The project export file to be imported' # rubocop:disable Scalability/FileUploads optional :name, type: String, desc: 'The name of the project to be imported. Defaults to the path of the project if not provided.' optional :namespace, type: String, desc: "The ID or name of the namespace that the project will be imported into. Defaults to the current user's namespace." optional :overwrite, type: Boolean, default: false, desc: 'If there is a project in the same namespace and with the same name overwrite it' @@ -38,12 +59,24 @@ module API desc: 'New project params to override values in the export' do use :optional_project_params end + optional 'file.path', type: String, desc: 'Path to locally stored body (generated by Workhorse)' + optional 'file.name', type: String, desc: 'Real filename as send in Content-Disposition (generated by Workhorse)' + optional 'file.type', type: String, desc: 'Real content type as send in Content-Type (generated by Workhorse)' + optional 'file.size', type: Integer, desc: 'Real size of file (generated by Workhorse)' + optional 'file.md5', type: String, desc: 'MD5 checksum of the file (generated by Workhorse)' + optional 'file.sha1', type: String, desc: 'SHA1 checksum of the file (generated by Workhorse)' + optional 'file.sha256', type: String, desc: 'SHA256 checksum of the file (generated by Workhorse)' + optional 'file.etag', type: String, desc: 'Etag of the file (generated by Workhorse)' + optional 'file.remote_id', type: String, desc: 'Remote_id of the file (generated by Workhorse)' + optional 'file.remote_url', type: String, desc: 'Remote_url of the file (generated by Workhorse)' end desc 'Create a new project import' do detail 'This feature was introduced in GitLab 10.6.' success Entities::ProjectImportStatus end post 'import' do + require_gitlab_workhorse! if with_workhorse_upload_acceleration? + key = "project_import".to_sym if throttled?(key, [current_user, key]) @@ -52,8 +85,6 @@ module API render_api_error!({ error: _('This endpoint has been requested too many times. Try again later.') }, 429) end - validate_file! - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/42437') namespace = if import_params[:namespace] @@ -62,11 +93,21 @@ module API current_user.namespace end + # TODO: remove the condition after the WH version including + # https://gitlab.com/gitlab-org/gitlab-workhorse/-/merge_requests/459 + # is deployed and GITLAB_WORKHORSE_VERSION is updated accordingly. + file = if with_workhorse_upload_acceleration? + import_params[:file] || bad_request!('Unable to process project import file') + else + validate_file! + import_params[:file]['tempfile'] + end + project_params = { path: import_params[:path], namespace_id: namespace.id, name: import_params[:name], - file: import_params[:file]['tempfile'], + file: file, overwrite: import_params[:overwrite] } |