Update virtual registry gates to check that virtual registry setting is enabled
What does this MR do and why?
This MR adds in an additional gate to check if the virtual registries setting enabled is set to true:
- virtual registries base controller
- Query on the group type to list virtual registries
- Query to return a virtual registry and the upstream registry
- Upstream create mutation
- API shared setup
- Package registries menu
There are existing checks that we do on the maven virtual registries endpoints (licence, dependency proxy enabled, feature flag and permissions check). This setting for enabled/disabled is something the customer will be able to control in their package and registries setting in the UI to disable virtual registries for a group.
By default it is enabled. In the model the find_for_group method, will initialize a new virtual registries setting object if one does not exist, and the default value is for enabled is true.
NOTE: There is this existing follow up issue to refactor the gates to reduce duplication. There are some tests that could do with less duplication as well. Instead of doing both in the one MR, I will do the refactor after this feature is in.
I have refactored the checks for the gates and added to the model in this MR. The reasons for this are, the performance duo report was returning comments on the usage of the find_for_group calls to the db. So I wanted to utilise the request store to cache the setting for the duration of the request. There is also another MR in review that has refactored these checks into the model, so I have followed the same pattern here.
I will leave any test refactoring for the linked issue.
References
Screenshots or screen recordings
See validation steps below for screenshots
How to set up and validate locally
Setup:
- Ensure the below feature flags are enabled and you have activated your EE subscription locally.
Feature.enable(:maven_virtual_registry)
Feature.enable(:ui_for_virtual_registries)
- The default value for the virtual registries setting enabled field is true. So nothing extra needs to be done.
- Ensure dependency proxy is enabled (this is also enabled by default).
- Ensure you have activated your EE license locally
- Log in to
http://gdk.test:3000/twitter
. Ensure you are the group owner. - In another tab go to graphiql
http://gdk.test:3000/-/graphql-explorer
Validate that the UI, API and GraphQL continues to work and also responds to setting
Validate package and registries menu:
- Go to graphiql and run the below mutation to update enabled to false.
mutation UpdateVirtualRegistriesSetting($input: UpdateVirtualRegistriesSettingInput!) {
updateVirtualRegistriesSetting(input: $input) {
virtualRegistriesSetting {
enabled
}
}
}
{
"input": {
"groupPath": "twitter",
"enabled": false
}
}
- Go back to gdk.test and refresh the page. Virtual registry will no longer appear in the menu.
Validate Create registry
- Run the mutation in graphiql to set enabled back to true.
- Click on create registry
- Set a name and click on create registry
- Run mutation to switch enabled to false
- Click on create registry
- You should see a 404
Validate Edit registry
- Run the mutation in graphiql to set enabled back to true.
- Go to the list view
- Select edit icon next to registry or select a registry and then select edit
- Set enabled back to false in graphiql
- And click edit again and you should see a 404 page rendered
Validate virtual registries list view groups/:id/-/virtual_registries
- Run the mutation to set enabled to true.
- Click on virtual registry in the menu which takes you to
groups/:id/-/virtual_registries
- Back in graphiql, run the mutation to set enabled to false.
- Go back and refresh the page, you should see a 404.
Validate virtual registries list GraphQL query
- Set enabled to true
- Go to graphiql
- Run the below query:
query getMavenVirtualRegistries($groupPath: ID!) {
group(fullPath: $groupPath) {
id
mavenVirtualRegistries {
nodes {
id
name
}
}
}
}
------------
variables:
{
"groupPath": "twitter"
}
- Set enabled to false and run the above query again, null will be returned
Validate get maven registry GraphQL query
- In graphiql, set enabled to true
- Get an id for a registry from the previous query to list registries
- Run query with the id, should return the individual registry:
query getMavenVirtualRegistry($id: VirtualRegistriesPackagesMavenRegistryID!) {
mavenVirtualRegistry(id: $id) {
id
updatedAt
name
}
}
------
variables:
{
"id": "gid://gitlab/VirtualRegistries::Packages::Maven::Registry/5"
}
- Set enabled to false
- Run query again, and null should be returned
Validate create maven upstream registry
- Go back to http://gdk.test:3000/groups/twitter/-/virtual_registries/maven
- Select a virtual registry again and select create upstream.
- Set enabled to false
- Complete form and then click create upstream
- There should be a something went wrong error
- Checking the network tab we'll see the below error response for the mutation
Validate get upstream registries
- Click on virtual registry again.
- Set enabled to false
- Refresh page and you will the 404 page.
API
GET /groups/:id/-/virtual_registries/packages/maven/registries
- In your browser go to
http://gdk.test:3000/api/v4/groups/<your group id>/-/virtual_registries/packages/maven/registries
- Update enabled to false and refresh page and a 404 should be returned.
POST /groups/:id/-/virtual_registries/packages/maven/registries
- Create an access token, owner and api setting.
- Run this curl command:
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data '{"name": "my-virtual-registry", "description": "My virtual registry"}' \
--url "https://gdk.test:3000/api/v4/groups/<your group id>/-/virtual_registries/packages/maven/registries"
- You should receive a 404 as enabled is still false from previous example
GET /virtual_registries/packages/maven/registries/:id
- This one can be done back in the browser if you prefer. Go back to your virtual registries, select one and get the id.
- Run this in your browser
http://gdk.test:3000/api/v4/virtual_registries/packages/maven/registries/<your registry id>
- Update enabled to false back in GraphQL explorer and refresh page, and a 404 should be returned.
PATCH /virtual_registries/packages/maven/registries/:id
- Run this curl command using the same access token from earlier, a 404 should be returned.
curl --request PATCH \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--data '{"name": "my-virtual-registry", "description": "My virtual registry"}' \
--url "http://gdk.test:3000/api/v4/virtual_registries/packages/maven/registries/2"
- Update enabled to true and run the curl command again a 200 should be returned.
DELETE /virtual_registries/packages/maven/registries/:id
- Run the delete curl command with your registry id, registry will be deleted from list:
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" \
--header "Accept: application/json" \
--url "http://gdk.test:3000/api/v4/virtual_registries/packages/maven/registries/2"
- Update enabled to false, and run curl command again and a 404 should be returned:
GET /groups/:id/-/virtual_registries/packages/maven/upstreams
- Run this in the browser and a 404 should be returned
http://gdk.test:3000/api/v4/groups/<your group id>/-/virtual_registries/packages/maven/upstreams
- Update enabled to true and refresh the page, and the upstreams should be returned.
POST /groups/:id/-/virtual_registries/packages/maven/upstreams/test
- Run the below curl command and a success true should be returned.
- Update enabled to false and a 404 will be returned
GET /virtual_registries/packages/maven/registries/:id/upstreams
- In the browser run this
http://gdk.test:3000/api/v4/virtual_registries/packages/maven/registries/1/upstreams
, and a 404 should be returned.
- Update enabled to true and refresh page and upstreams will be returned.
POST /virtual_registries/packages/maven/registries/:id/upstreams
- Run the below curl command and a success response should be received.
- Update enabled to false and a 404 should be received
GET /virtual_registries/packages/maven/upstreams/:id
- Using the id for the upstream from the previous POST command, run this in the browser. A 404 should be returned.
- Update enabled to true and refresh page and the upstream should be returned.
PATCH /virtual_registries/packages/maven/upstreams/:id
- Run the below curl command and a 200 response should be returned
- Update enabled to false, and a 404 should be returned
PATCH /virtual_registries/packages/maven/registry_upstreams/:id
- Run the below curl command and a 404 should be returned
- Update enabled to true and a 200 should be returned.
The remainder of api endpoints all have the same api shared setup included (include ::API::Concerns::VirtualRegistries::Packages::Maven::SharedSetup
), so these will also return the same behaviour when enable is true or false.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #554069