Skip to content

Update maven upstream credentials handling

Context

In Add models for Virtual Registries, part 1/2 (!156930 - merged), we introduced several models for the upcoming Maven virtual registry feature.

For more details, read the context on that MR.

We introduced an upstream model that is responsible to store details about an upstream. Among them, the url of the upstream and its credentials.

In our local testing, we saw that we were missing a callback: when the url of the upstream is updated, we should reset the credentials. Credentials are tied to urls so a change in the url should cascade a credentials reset.

That's the goal of this MR.

🤔 What does this MR do and why?

  • Add a callback to Maven upstreams so that when the url is changed, the credentials structure is reset (or set to empty).
  • Also fix an issue we spotted when passing the username and password directly to .new.
  • Update the related specs.

The entire Maven virtual registry feature is still in development that is be behind a feature flag.

🏁 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.

🦄 Screenshots or screen recordings

🤷

How to set up and validate locally

At the time of this writing, we only have models for the Maven virtual registry feature. No services or logic has been implemented yet.

Thus, the only way to test this is through a rails console:

# Trying out passing username and password values through the initializer. This is a part fixed by this MR

u = VirtualRegistries::Packages::Maven::Upstream.create!(group: Group.first, url: 'http://bananas.test', username: 'user', password: 'password')
u.username
=> "user"

u.password
=> "password"

u.credentials
=> {"username"=>"user", "password"=>"password"}

# Update the url

u.update!(url: 'http://bananas2.test')

# credentials should be reset
u.username
=> nil

u.password
=> nil

u.credentials
=> {"username"=>nil, "password"=>nil}

Things are behaving as expected 🎉

Related to #467972 (closed)

Edited by David Fernandez

Merge request reports

Loading