diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
commit | db384e6b19af03b4c3c82a5760d83a3fd79f7982 (patch) | |
tree | 34beaef37df5f47ccbcf5729d7583aae093cffa0 /lib/api/nuget_project_packages.rb | |
parent | 54fd7b1bad233e3944434da91d257fa7f63c3996 (diff) |
Add latest changes from gitlab-org/gitlab@16-3-stable-eev16.3.0-rc42
Diffstat (limited to 'lib/api/nuget_project_packages.rb')
-rw-r--r-- | lib/api/nuget_project_packages.rb | 94 |
1 files changed, 64 insertions, 30 deletions
diff --git a/lib/api/nuget_project_packages.rb b/lib/api/nuget_project_packages.rb index 2716d6f0b64..bff645700f5 100644 --- a/lib/api/nuget_project_packages.rb +++ b/lib/api/nuget_project_packages.rb @@ -98,9 +98,30 @@ module API created! end + def publish_package(symbol_package: false) + upload_nuget_package_file(symbol_package: symbol_package) do |package| + track_package_event( + symbol_package ? 'push_symbol_package' : 'push_package', + :nuget, + **{ category: 'API::NugetPackages', + project: package.project, + namespace: package.project.namespace }.tap { |args| args[:feed] = 'v2' if request.path.include?('nuget/v2') } + ) + end + rescue ObjectStorage::RemoteStoreError => e + Gitlab::ErrorTracking.track_exception(e, extra: { file_name: params[:file_name], project_id: project_or_group.id }) + + forbidden! + end + def required_permission :read_package end + + def format_filename(package) + return "#{params[:package_filename]}.#{params[:format]}" if Feature.disabled?(:nuget_normalized_version, project_or_group) || package.version == params[:package_version] + return "#{params[:package_filename].sub(params[:package_version], package.version)}.#{params[:format]}" if package.normalized_nuget_version == params[:package_version] + end end params do @@ -159,8 +180,9 @@ module API requires :package_filename, type: String, desc: 'The NuGet package filename', regexp: API::NO_SLASH_URL_PART_REGEX, documentation: { example: 'mynugetpkg.1.3.0.17.nupkg' } end get '*package_version/*package_filename', format: [:nupkg, :snupkg], urgency: :low do - filename = "#{params[:package_filename]}.#{params[:format]}" - package_file = ::Packages::PackageFileFinder.new(find_package(params[:package_name], params[:package_version]), filename, with_file_name_like: true) + package = find_package(params[:package_name], params[:package_version]) + filename = format_filename(package) + package_file = ::Packages::PackageFileFinder.new(package, filename, with_file_name_like: true) .execute not_found!('Package') unless package_file @@ -179,7 +201,7 @@ module API end end - # To support an additional authentication option for download endpoints, + # To support an additional authentication option for publish endpoints, # we redefine the `authenticate_with` method by combining the previous # authentication option with the new one. authenticate_with do |accept| @@ -191,7 +213,7 @@ module API namespace '/nuget' do # https://docs.microsoft.com/en-us/nuget/api/package-publish-resource - desc 'The NuGet Package Publish endpoint' do + desc 'The NuGet V3 Feed Package Publish endpoint' do detail 'This feature was introduced in GitLab 12.6' success code: 201 failure [ @@ -207,19 +229,7 @@ module API use :file_params end put urgency: :low do - upload_nuget_package_file do |package| - track_package_event( - 'push_package', - :nuget, - category: 'API::NugetPackages', - project: package.project, - namespace: package.project.namespace - ) - end - rescue ObjectStorage::RemoteStoreError => e - Gitlab::ErrorTracking.track_exception(e, extra: { file_name: params[:file_name], project_id: project_or_group.id }) - - forbidden! + publish_package end desc 'The NuGet Package Authorize endpoint' do @@ -252,19 +262,7 @@ module API use :file_params end put 'symbolpackage', urgency: :low do - upload_nuget_package_file(symbol_package: true) do |package| - track_package_event( - 'push_symbol_package', - :nuget, - category: 'API::NugetPackages', - project: package.project, - namespace: package.project.namespace - ) - end - rescue ObjectStorage::RemoteStoreError => e - Gitlab::ErrorTracking.track_exception(e, extra: { file_name: params[:file_name], project_id: project_or_group.id }) - - forbidden! + publish_package(symbol_package: true) end desc 'The NuGet Symbol Package Authorize endpoint' do @@ -280,6 +278,42 @@ module API put 'symbolpackage/authorize', urgency: :low do authorize_nuget_upload end + + namespace '/v2' do + desc 'The NuGet V2 Feed Package Publish endpoint' do + detail 'This feature was introduced in GitLab 16.2' + success code: 201 + failure [ + { code: 400, message: 'Bad Request' }, + { code: 401, message: 'Unauthorized' }, + { code: 403, message: 'Forbidden' }, + { code: 404, message: 'Not Found' } + ] + tags %w[nuget_packages] + end + + params do + use :file_params + end + put do + publish_package + end + + desc 'The NuGet V2 Feed Package Authorize endpoint' do + detail 'This feature was introduced in GitLab 16.2' + success code: 200 + failure [ + { code: 401, message: 'Unauthorized' }, + { code: 403, message: 'Forbidden' }, + { code: 404, message: 'Not Found' } + ] + tags %w[nuget_packages] + end + + put 'authorize', urgency: :low do + authorize_nuget_upload + end + end end end end |