From 2bf6c2efbcdcb1ccbb2da6fc959a5f1fe28d19aa Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Wed, 21 May 2025 17:59:17 -0600 Subject: [PATCH] fix: strip repository for login for backwards compatibility Signed-off-by: Terry Howe --- pkg/registry/client.go | 15 +++++++++++++++ pkg/registry/client_test.go | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/registry/client.go b/pkg/registry/client.go index de7e636e1..a27559e4d 100644 --- a/pkg/registry/client.go +++ b/pkg/registry/client.go @@ -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}) } diff --git a/pkg/registry/client_test.go b/pkg/registry/client_test.go index 4c5a78849..5765134ba 100644 --- a/pkg/registry/client_test.go +++ b/pkg/registry/client_test.go @@ -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")) +}