Skip to content

Protected containers: New GraphQL field "protectionRuleExists"

  • 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?

  • This MR is preparation (pre-work) for a feature similar to the Protected badge in the context of "Protected packages":
  • When working on a similar feature in the context of "Protected packages", it was necessary to add a new GraphQL field "protectionRuleExists" to determine if a protection rule exists for a given package, see !146206 (merged) and !141134 (merged)
  • This MR focusses on adding this a new GraphQL field "protectionRuleExists" to the container repository type that can be consumed in upcoming MRs

🛠 with at Siemens

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.

MR Checklist (@gerardo-navarro)

DB Query

WITH "container_names_and_types_cte" AS MATERIALIZED (
  SELECT *
  FROM unnest(ARRAY['flightjs/flight/5','flightjs/flight/4','flightjs/flight/3','flightjs/flight/2','flightjs/flight']) AS x(repository_path)
)
SELECT
  container_names_and_types_cte."repository_path",
  EXISTS(
    SELECT 1
    FROM "container_registry_protection_rules"
    WHERE "container_registry_protection_rules"."project_id" = 7 AND
      (container_names_and_types_cte."repository_path" ILIKE REPLACE(REPLACE(REPLACE(repository_path_pattern, '%', '\%'), '_', '\_'), '*', '%'))
  ) AS protected
FROM container_names_and_types_cte

Screenshots or screen recordings

grafik

How to set up and validate locally

  1. Execute the following GraphQL query
curl --request POST \
  --url http://gdk.test:3000/api/graphql \
  --header 'Authorization: Bearer ypCa3Dzb23o5nvsixwPA' \
  --header 'Content-Type: application/json' \
  --data '{"query":"query {\n\tproject(fullPath: \"flightjs/Flight\") {\n\t\tcontainerRepositories{\n\t\t\tnodes {\n\t\t\t\tid\n\t\t\t\tpath\n\t\t\t\tname\n\t\t\t\tprotectionRuleExists\n\t\t\t}\n\t\t}\n\t}\n}\n"}'
  1. Look at the console output; you should just see one SQL query related to the new field "protectionRuleExists".

Related to #441346

Edited by Gerardo Navarro

Merge request reports