Commit c45ecaf9 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add support for maven package download via API [ci skip]

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 87ff4029
...@@ -4,5 +4,18 @@ class Packages::PackageFileUploader < GitlabUploader ...@@ -4,5 +4,18 @@ class Packages::PackageFileUploader < GitlabUploader
storage_options Gitlab.config.packages storage_options Gitlab.config.packages
# TODO: Implement me def store_dir
dynamic_segment
end
private
def dynamic_segment
File.join(disk_hash[0..1], disk_hash[2..3], disk_hash,
'packages', model.package.id.to_s, 'files', model.id.to_s)
end
def disk_hash
@disk_hash ||= Digest::SHA2.hexdigest(model.package.project_id.to_s)
end
end end
...@@ -172,6 +172,7 @@ module API ...@@ -172,6 +172,7 @@ module API
mount ::API::License mount ::API::License
mount ::API::ProjectMirror mount ::API::ProjectMirror
mount ::API::ProjectPushRule mount ::API::ProjectPushRule
mount ::API::Packages
## EE-specific API V4 endpoints END ## EE-specific API V4 endpoints END
route :any, '*path' do route :any, '*path' do
......
module API
class Packages < Grape::API
content_type :md5, 'text/plain'
content_type :sha1, 'text/plain'
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
desc 'Download the maven package file' do
detail 'This feature was introduced in GitLab 11.3'
end
get ':id/maven/*file_path' do
checksum = %w(md5 sha1).include?(params[:format])
file_path, _, file_name = params[:file_path].rpartition('/')
file_name = file_name + '.' + params[:format] unless checksum
app_path, _, version = file_path.rpartition('/')
app_group, _, app_name = app_path.rpartition('/')
metadata = ::Packages::MavenMetadatum.find_by(app_group: app_group,
app_name: app_name,
app_version: version)
package_file = metadata.package.package_files.find_by(file: file_name)
if checksum
case params[:format]
when 'md5'
package_file.file_md5
when 'sha1'
package_file.file_sha1
end
else
present_carrierwave_file!(package_file.file)
end
end
desc 'Upload the maven package file' do
detail 'This feature was introduced in GitLab 11.3'
end
post ':id/maven/*file_path' do
# parse file path, create an upload, save record in database
end
end
end
end
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