Add virtual registry upstreams create and update services
🐦⬛ Context
In Maven virtual registries: local upstreams backe... (#566217) • David Fernandez • 18.8 • At risk, we're working towards support local upstreams in the Maven virtual registries.
You can look at more details in !207117 (merged).
We started the changes on the API endpoints but they were too large (see !215982).
This MR is an extraction of some parts of that MR:
- the create/update services for upstreams to centralize common logic, for example, user authorization.
- the related specs.
- update all call sites (Rest API endpoint / GraphQL) to use the new services instead of a duplicated logic.
Looking at the logic of the create and update services, they are not really tied to Maven but they still handle local upstreams. Thus, we can have a pretty generic service for upstreams of any artifact type handled by the virtual registry.
There is already a generic create upstream service. That service doesn't appear to be used anywhere, so the create service introduced by this MR is going to replace it.
🤔 What does this MR do and why?
- introduce the create and update maven upstream services.
- add the related specs.
- update the Rest API endpoints and graphql mutations to use these new services.
Note that the services are ready to handle local upstreams but that part will not be used yet as the Rest API endpoints and graphql parts inputs have not been updated = external clients can't create local upstreams (yet).
📖 References
- Maven virtual registries: local upstreams backe... (#566217) • David Fernandez • 18.8 • At risk
- !207117 (merged)
📺 Screenshots or screen recordings
No UI changes.
🧑🔬 How to set up and validate locally
Requirements:
- An EE license
- A top level group
- A Personal access token with
apiscope for a maintainer of that top level group.
The parent object of maven upstreams is a maven virtual registry. Let's create that in a rails console:
top_level_group = Group.find(<top_level_group.id>)
FactoryBot.create(:)
🧑🔬 How to set up and validate locally
Requirements:
- An EE license
- A top level group
- A Personal access token with
apiscope for a maintainer of that top level group.
The parent object of maven upstreams is a maven virtual registry. Let's create that in a rails console:
top_level_group = Group.top_level.sample(1).first
registry = FactoryBot.create(:virtual_registries_packages_maven_registry, group: top_level_group) # note the registry id
We're ready for the tests.
1️⃣ Rest API
Let's create maven upstream under our registry:
$ curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "http://gdk.test:8000/api/v4/virtual_registries/packages/maven/registries/<registry_id>/upstreams?url=https://repo.maven.apache.org/maven2&name=test" | jq
(note the upstream id)
The upstream is correctly created
Update a Maven upstream via REST API
$ curl --request PATCH --header "PRIVATE-TOKEN: <your_access_token>" "http://gdk.test:8000/api/v4/virtual_registries/packages/maven/upstreams/<upstream_id>?name=test2"
You should get a 200 Ok.
You can verify the update with
$ curl --header "PRIVATE-TOKEN: <your_access_token>" "http://gdk.test:8000/api/v4/virtual_registries/packages/maven/upstreams/<upstream_id>" | jq
2️⃣ GraphQL
Let's use GraphQL to create a maven upstream.
mutation {
mavenUpstreamCreate(input: {
id: "gid://gitlab/VirtualRegistries::Packages::Maven::Registry/<registry_id>",
name: "test graphQL",
url: "https://repo.maven.apache.org/maven3",
description: "test graphQL",
cacheValidityHours: 24,
metadataCacheValidityHours: 1
}) {
upstream {
id
name
url
description
cacheValidityHours
metadataCacheValidityHours
}
errors
}
}
Verify the presence of the two upstreams with:
query {
virtualRegistriesPackagesMavenRegistry(id: "gid://gitlab/VirtualRegistries::Packages::Maven::Registry/<registry_id>") {
id
name
registryUpstreams {
id
position
upstream {
id
url
name
description
cacheValidityHours
metadataCacheValidityHours
}
}
}
}
All working as expected
🏎️ 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.