Commit 49452493 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Use workhorse for maven package file upload [ci skip]

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 0a18081d
...@@ -75,14 +75,46 @@ module API ...@@ -75,14 +75,46 @@ module API
requires :app_version, type: String, desc: 'Package version' requires :app_version, type: String, desc: 'Package version'
requires :file_name, type: String, desc: 'Package file name' requires :file_name, type: String, desc: 'Package file name'
end end
put ':id/packages/maven/*app_group/:app_name/:app_version/:file_name/authorize', requirements: MAVEN_ENDPOINT_REQUIREMENTS do
not_allowed! unless Gitlab.config.packages.enabled
require_gitlab_workhorse!
Gitlab::Workhorse.verify_api_request!(headers)
status 200
content_type Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE
::Packages::PackageFileUploader.workhorse_authorize(has_length: true)
end
desc 'Upload the maven package file' do
detail 'This feature was introduced in GitLab 11.3'
end
params do
requires :app_group, type: String, desc: 'Package group id'
requires :app_name, type: String, desc: 'Package artifact id'
requires :app_version, type: String, desc: 'Package version'
requires :file_name, type: String, desc: 'Package file name'
optional 'file.path', type: String, desc: %q(path to locally stored body (generated by Workhorse))
optional 'file.name', type: String, desc: %q(real filename as send in Content-Disposition (generated by Workhorse))
optional 'file.type', type: String, desc: %q(real content type as send in Content-Type (generated by Workhorse))
optional 'file.size', type: Integer, desc: %q(real size of file (generated by Workhorse))
optional 'file.sha256', type: String, desc: %q(sha256 checksum of the file (generated by Workhorse))
end
put ':id/packages/maven/*app_group/:app_name/:app_version/:file_name', requirements: MAVEN_ENDPOINT_REQUIREMENTS do put ':id/packages/maven/*app_group/:app_name/:app_version/:file_name', requirements: MAVEN_ENDPOINT_REQUIREMENTS do
not_allowed! unless Gitlab.config.packages.enabled
require_gitlab_workhorse!
file_name, format = extract_format(params[:file_name]) file_name, format = extract_format(params[:file_name])
string_file = env['api.request.input']
uploaded_file = UploadedFile.from_params(params, :file, ::Packages::PackageFileUploader.workhorse_local_upload_path)
bad_request!('Missing package file!') unless uploaded_file
metadata = ::Packages::MavenMetadatum.find_by(app_group: params[:app_group], metadata = ::Packages::MavenMetadatum.find_by(app_group: params[:app_group],
app_name: params[:app_name], app_name: params[:app_name],
app_version: params[:app_version]) app_version: params[:app_version])
# TODO: Refactor. We don't need to read file for every request, only metadata and md5/sha1
string_file = File.read(uploaded_file)
unless metadata unless metadata
if file_name == MAVEN_METADATA_FILE if file_name == MAVEN_METADATA_FILE
return unless valid_metadata_xml?(string_file) return unless valid_metadata_xml?(string_file)
...@@ -112,7 +144,7 @@ module API ...@@ -112,7 +144,7 @@ module API
package_file.file_type = file_name.rpartition('.').last package_file.file_type = file_name.rpartition('.').last
# Convert string into CarrierWave compatible StringIO object # Convert string into CarrierWave compatible StringIO object
package_file.file = CarrierWaveStringFile.new(string_file) package_file.file = uploaded_file
end end
package_file.save! package_file.save!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment