Skip to content

Add put API endpoint to support uploading recipe package files

What does this MR do and why?

Add put API endpoint to support uploading recipe package files

This MR include the new endpoint, the corresponding workhorse endpoint and the backend code to create recipe revision when uploading a file. Of course, this MR also include tests relative to these changes.

Changelog: added

The endpoint follows this format:

Put /api/v4/projects/:id/packages/conan/v2/conans/:package_name/:package_version/:package_username/:package_channel/revisions/:recipe_revision/files/:file_name

Notes:

  • Protected by the conan_package_revisions_support feature flag

References

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

To test the Conan package download endpoint, you'll need to:

  1. Set up the feature flag
  2. Get a Conan authentication token
  3. Test the endpoint with curl

1. Feature Flag Setup

For GDK, open rails console (docs):

gdk rails console

Enable/disable the feature flag:

# Enable
Feature.enable(:conan_package_revisions_support)

# Verify
Feature.enabled?(:conan_package_revisions_support)

# Disable
Feature.disable(:conan_package_revisions_support)

2. Get Conan Authentication Token

First, generate a base64-encoded Basic Auth token:

# Replace with your username and PAT
echo -n "USERNAME:glpat-YOUR-TOKEN" | base64

Then use it to get a Conan JWT token:

curl --request GET \
  --url 'http://localhost:3000/api/v4/projects/1/packages/conan/v1/users/authenticate' \
  --header 'Authorization: Basic <YOUR-BASE64-TOKEN>' \
  --header 'Accept: text/plain'

3. Test API endpoint

To test we need 1 project where your token has access. In requests below, replace <project_id> with your corresponding project id.

Create a test conanfile.py

echo "class UploadV2Package:" > conanfile.py

Upload using the new v2 endpoint
curl --request PUT \
  --form 'file=@conanfile.py' \
'http://localhost:3000/api/v4/projects/<project_id>/packages/conan/v2/conans/upload-v2-package/1.0.0/user/stable/revisions/123456789012345678901234567890ab/files/conanfile.py' \
  --header 'Authorization: Bearer <YOUR-CONAN-JWT-TOKEN>'

Test with Feature Flag Off

Expected response:

  • status: 404 Not Found
  • body: {"message": "404 'conan_package_revisions_support' feature flag is disabled Not Found"}

Test with Feature Flag ON

Expected response:

  • status: 200

  • body, something like:

    {
        "id": 185,
        "package_id": 48,
        "created_at": "2025-02-13T14:59:32.210Z",
        "updated_at": "2025-02-13T14:59:32.210Z",
        "size": 240,
        "file_store": 1,
        "file_md5": "28dd69a2d017affa93c7c8848dfaaae2",
        "file_sha1": "d73069dccdbaaa93f18f1ceb304ee7e190daa15e",
        "file_name": "conanfile.py",
        "file": {
            "url": "/94/00/9400f1b21cb527d7fa3d3eabba93557a18ebe7a2ca4e471cfe5e4c5b4ca7f767/packages/48/files/185/conanfile.py"
        },
        "file_sha256": null,
        "verification_retry_at": null,
        "verified_at": null,
        "verification_failure": null,
        "verification_retry_count": null,
        "verification_checksum": null,
        "verification_state": 0,
        "verification_started_at": null,
        "status": "default",
        "file_final_path": null,
        "project_id": 19,
        "new_file_path": null
    }

Verify the upload through the GitLab UI:

  • Go to your project
  • Navigate to "Packages & Registries" > "Package Registry"
  • Confirm the Conan package appears

Or by calling the get endpoint

curl --request GET \
  --url 'http://localhost:3000/api/v4/projects/<project_id>/packages/conan/v2/conans/upload-v2-package/1.0.0/user/stable/revisions/123456789012345678901234567890ab/files/conanfile.py' \
  --header 'Authorization: Bearer <YOUR-CONAN-JWT-TOKEN>'

Related to #333033 (closed)

\cc @mbo5be

Edited by Océane Legrand

Merge request reports

Loading