Skip to content

Protected containers: Graphql mutation for creating protection rules

What does this MR do and why?

🛠 with at Siemens

Screenshots or screen recordings

With this MR, it is possible to send graphql requests in order to create new container registry protection rules.

The body of the graphql request looks like this

mutation {
	createContainerRegistryProtectionRule(
		input: {
			projectPath: "flightjs/Flight"
			containerPathPattern: "@flight/flight-*"
			pushProtectedUpToAccessLevel: MAINTAINER
			deleteProtectedUpToAccessLevel: OWNER
		}
	) {
		containerRegistryProtectionRule {
			id
			containerPathPattern
			pushProtectedUpToAccessLevel
			deleteProtectedUpToAccessLevel
		}
		errors
	}
}

image

How to set up and validate locally

  1. Enable feature flag via rails c
Feature.enable(:container_registry_protected_containers)
  1. Now, you should be able to send mutation requests via the graphql api
curl --request POST \
  --url http://gdk.test:3000/api/graphql \
  --header 'Authorization: Bearer ypCa3Dzb23o5nvsixwPA' \
  --header 'Content-Type: application/json' \
  --cookie 'perf_bar_enabled=true; BetterErrors-2.10.1-CSRF-Token=0b882179-5e4a-431b-a420-2be3701cece8' \
  --data '{"query":"mutation {\n\tcreateContainerRegistryProtectionRule(\n\t\tinput: {\n\t\t\tprojectPath: \"flightjs/Flight\"\n\t\t\tcontainerPathPattern: \"@flight/flight-*\"\n\t\t\tpushProtectedUpToAccessLevel: MAINTAINER\n\t\t\tdeleteProtectedUpToAccessLevel: OWNER\n\t\t}\n\t) {\n\t\tcontainerRegistryProtectionRule {\n\t\t\tid\n\t\t\tcontainerPathPattern\n\t\t\tpushProtectedUpToAccessLevel\n\t\t\tdeleteProtectedUpToAccessLevel\n\t\t}\n\t\terrors\n\t}\n}\n"}'

Todos

  • Think about removing code duplication
  • Think about extracting common functionality from package protection rules
  • Please create feature flag roll out issue, see #429074

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 #427547 (closed)

Edited by Gerardo Navarro

Merge request reports