Skip to content

Protected packages: GraphQL api for creating package protection rules

What does this MR do and why?

  • This MR adds a new graphql endpoint for creating package protection rules.
  • This MR is part of the EPIC &5574 and is planned to be included in the 1st version of this feature, see &5574 (comment 1437348728)

🛠 with at Siemens

Screenshots or screen recordings

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

The body of the graphql request looks like this

mutation {
	createPackageProtectionRule(
		input: {
			projectPath: "flightjs/Flight"
			packageNamePattern: "@flight/flight-js"
			packageType: NPM
			pushProtectedUpToAccessLevel: OWNER
		}
	) {
		clientMutationId
		errors
	}
}

grafik

How to set up and validate locally

  1. Enable feature flag via rails c
Feature.enable(:packages_protected_packages)
  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\tcreatePackagesProtectionRule(\n\t\tinput: {\n\t\t\tprojectPath: \"flightjs/Flight\"\n\t\t\tpackageNamePattern: \"@flight/flight-js--*\"\n\t\t\tpackageType: NPM\n\t\t\tpushProtectedUpToAccessLevel: MAINTAINER\n\t\t}\n\t) {\n\t\tclientMutationId\n\t\terrors\n\t}\n}\n"}'

TODOs

  • Consider feature flag when resolving the query
  • Include tests for disabled feature flag
  • Add test for the policy
  • Add test for new package pprotection rule graphql type
  • change feature category

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

Edited by Gerardo Navarro

Merge request reports