fix: strip repository for login for backwards compatibility

Signed-off-by: Terry Howe <terrylhowe@gmail.com>
pull/30897/head
Terry Howe 4 months ago
parent f147277a59
commit 2bf6c2efbc

@ -229,8 +229,23 @@ type (
}
)
// Added for backwards compatibility for Helm < 3.18.0 after moving to ORAS v2
// ref: https://github.com/helm/helm/issues/30873
// TODO: document that Helm 4 `registry login` does accept repositories
func stripRepository(host string) string {
if idx := strings.Index(host, "/"); idx != -1 {
host = host[:idx]
fmt.Printf("WARNING: Invalid registry passed: registries must NOT include a repository. Use %q instead\n", host)
return host
}
return host
}
// Login logs into a registry
func (c *Client) Login(host string, options ...LoginOption) error {
// This is the lowest available point to strip the repository
host = stripRepository(host)
for _, option := range options {
option(&loginOperation{host, c})
}

@ -31,3 +31,9 @@ func TestNewClientResolverNotSupported(t *testing.T) {
require.Equal(t, err, errDeprecatedRemote)
assert.Nil(t, client)
}
func TestStripRepository(t *testing.T) {
assert.Equal(t, "127.0.0.1:15000", stripRepository("127.0.0.1:15000/asdf"))
assert.Equal(t, "127.0.0.1:15000", stripRepository("127.0.0.1:15000/asdf/asdf"))
assert.Equal(t, "127.0.0.1:15000", stripRepository("127.0.0.1:15000"))
}

Loading…
Cancel
Save