Add create, update, and delete endpoints for tag protection rules in GraphQL
What does this MR do and why?
In this MR, we add mutations to create, update, and delete a tag protection rule in GraphQL. These mutations are behind the feature flag: container_registry_protected_tags
.
The added mutations are:
createContainerProtectionTagRule
DeleteContainerProtectionTagRule
UpdateContainerProtectionTagRule
These mutations will then be used by frontend to create, update, and delete tag rules.
MR acceptance checklist
How to set up and validate locally
☀️ Prerequisites
- Enable the feature flag:
container_registry_protected_tags
via the Rails console
Feature.enable(:container_registry_protected_tags)
- Prepare or create a project where you have
admin_container_image
permissions. If you don't have a project yet, easiest way is to create one so you are the owner and thus the admin.
💃 Mutation 1: Create
- Create a tag protection rule with the following code. Replace the
projectPath
with the full path of the project that you can get fromProject.find(id).full_path
whereid
is the ID of the project you are testing with.
mutation {
createContainerProtectionTagRule(input: {projectPath: "full/project/path", tagNamePattern: "v1", minimumAccessLevelForPush: ADMIN, minimumAccessLevelForDelete: ADMIN}) {
containerProtectionTagRule {
id
tagNamePattern
}
errors
}
}
When the call is successful, you will see errors: []
and the id
and tagNamePattern
of the created rule is returned. Sample successful result:
{
"data": {
"createContainerProtectionTagRule": {
"containerProtectionTagRule": {
"id": "gid://gitlab/ContainerRegistry::Protection::TagRule/7",
"tagNamePattern": "v1"
},
"errors": []
}
},
"correlationId": "01JFGSSVSFJ2GG1AQBSQD0AY0S"
}
💃 Mutation 2: Update
- You can use the created tag protection rule to test the update mutation. Getting the
id
that was returned during create, let's try to supply a differenttagNamePattern
.
mutation {
updateContainerProtectionTagRule(input: {id: "gid://gitlab/ContainerRegistry::Protection::TagRule/7", tagNamePattern: "v2"}) {
containerProtectionTagRule {
id
tagNamePattern
}
}
}
Once it is successful, it would also return empty errors as well as the id
and the new tagNamePattern
.
{
"data": {
"updateContainerProtectionTagRule": {
"containerProtectionTagRule": {
"id": "gid://gitlab/ContainerRegistry::Protection::TagRule/7",
"tagNamePattern": "v2"
}
}
},
"correlationId": "01JFGSX6RVQ611C416KTB6H0AD"
}
💃 Mutation 3: Delete
- Finally, we can also use the created tag to test the delete mutation. copying the
id
from the result,
mutation {
deleteContainerProtectionTagRule(input: {id: "gid://gitlab/ContainerRegistry::Protection::TagRule/7" }) {
containerProtectionTagRule {
id
}
}
}
And if successful, the result will be (note that the id
will be different depending on your setup):
{
"data": {
"deleteContainerProtectionTagRule": {
"containerProtectionTagRule": {
"id": "gid://gitlab/ContainerRegistry::Protection::TagRule/7"
}
}
},
"correlationId": "01JFGT43RMQD28JYNXSBFWTETA"
}
Related to #499870