Protected containers: Add PATCH REST API for container protection rules
-
Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA
What does this MR do and why?
Adds the PATCH route to the REST API for container protection rules to allow updating existing container protection rules.
This is part of #457518 (closed) and still behind a feature flag.
The MR is mostly equivalent to the MR that implements the PATCH request for package protection rules. There is one important difference, though: since minimum_access_level_for_push
and minimum_access_level_for_delete
can be empty, we have allow the API to clear existing values. Therefore, we allow submitting an empty string to differentiate between no value is set, don't change the existing record
, which should be possible for a PATCH
request, and clear the existing value
. With curl
, the difference would look like this:
Leave the existing value for minimum_access_level_for_push
unchanged:
curl --request PATCH \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--url "https://gitlab.example.com/api/v4/projects/7/registry/protection/rules/32" \
--data '{
"repository_path_pattern": "flight/flight-*"
}'
Clear the existing value for minimum_access_level_for_push
:
curl --request PATCH \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--url "https://gitlab.example.com/api/v4/projects/7/registry/protection/rules/32" \
--data '{
"repository_path_pattern": "flight/flight-*",
"minimum_access_level_for_push: ""
}'
MR acceptance checklist
MR Checklist ( @nwittstruck)
-
Changelog entry added, if necessary -
Documentation created/updated via this MR -
Documentation reviewed by technical writer or follow-up review issue created -
Tests added for this feature/bug -
Tested in all supported browsers -
Conforms to the code review guidelines -
Conforms to the merge request performance guidelines -
Conforms to the style guides -
Conforms to the javascript style guides - [] Conforms to the database guides
How to set up and validate locally
- Enable feature flag via
rails c
:
Feature.enable(:container_registry_protected_containers)
- Create a new container protection rule:
curl --request POST \
--url https://gdk.test:3443/api/v4/projects/7/registry/protection/rules \
--header 'Authorization: Bearer ypCa3Dzb23o5nvsixwPA' \
--header 'Content-Type: application/json' \
--data '{
"repository_path_pattern": "flightjs/flight-needs-to-be-a-unique-path",
"minimum_access_level_for_push": "maintainer",
"minimum_access_level_for_delete": "maintainer"
}'
- Now update the rule:
curl --request PATCH \
--url https://gdk.test:3443/api/v4/projects/7/registry/protection/rules/<ID_FROM_PREVIOUS_REQUEST> \
--header 'Authorization: Bearer ypCa3Dzb23o5nvsixwPA' \
--header 'Content-Type: application/json' \
--data '{
"repository_path_pattern": "flightjs/flight-is-now-a-different-path",
"minimum_access_level_for_push": "maintainer",
"minimum_access_level_for_delete": "maintainer"
}'
Related to #457518 (closed)