Skip to content

Add support for nuget v2 feed download endpoint

Moaz Khalifa requested to merge 416405-support-nuget-v2-download-endpoint into master

What does this MR do and why?

Add support for Nuget v2 feed file package download endpoint

To be able to download a NuGet package using the v2 feed, a download endpoint is provided by the OData metadata endpoint. It's the same download endpoint we have. The client receives it in the response of one of the OData package entry endpoints:

 <content type="application/zip" src="http://gdk.test:3000/api/v4/projects/<project_id>/packages/nuget/download/:package_name/:package_version/:package_filename"/>

Here's the sequence of requests in case of installing a package using choco or nuget which supports NuGet v2 feed:

  choco install PackageName -Source gitlab -Version 1.0.8
  --or
  nuget install PackageName -Source gitlab -Version 1.0.8
  1. GET http://gdk.test:3000/api/v4/projects/<project_id>/packages/nuget/v2/
  2. GET http://gdk.test:3000/api/v4/projects/<project_id>/packages/nuget/v2/$metadata
  3. GET http://gdk.test:3000/api/v4/projects/<project_id>/packages/nuget/v2/Packages(Id='packagename',Version='1.0.8')
  4. GET http://gdk.test:3000/api/v4/projects/<project_id>/packages/nuget/download/packagename/1.0.8/packagename.1.0.8.nupkg

NOTE: The package version must be provided in the install command, otherwise, the odata metadata endpoint will return an empty version in its response and the client (choco or nuget) will display this error: Value cannot be null or an empty string. Parameter name: version

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. on macOS, install mono
  2. Download the source code of choco 1.3.1: https://github.com/chocolatey/choco/releases/download/1.3.1/chocolatey.v1.3.1.tar.gz
  3. Extract the downloaded file and navigate to the root of the extracted folder in your terminal.
  4. Run the following command to add your GDK as NuGet v2 source:
mono choco.exe source add -n=gitlab -s "'http://gdk.test:3000/api/v4/projects/<project_id>/packages/nuget/v2/'" -u=<gitlab_username> -p=<PAT>
  1. Try to install a published NuGet package or publish a new one to test with:
 mono choco.exe install <package_name> -Source gitlab -Version <package_version>
  1. Packages should be installed successfully.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #416405 (closed)

Edited by Moaz Khalifa

Merge request reports