From 217971d48144e5cf3f27cebd220d9004b00221c7 Mon Sep 17 00:00:00 2001 From: Carston Schilds Date: Tue, 25 Jun 2024 15:28:25 -0700 Subject: [PATCH] re-introduced support for port numbers in docker registry URL Signed-off-by: Carston Schilds (cherry picked from commit 2380481609f034c4c6a9dec705cfd171783eeb37) Signed-off-by: Sebastiaan van Stijn --- cli/config/credentials/file_store.go | 5 ++++- cli/config/credentials/file_store_test.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cli/config/credentials/file_store.go b/cli/config/credentials/file_store.go index 99631bbf4c..2b37769c36 100644 --- a/cli/config/credentials/file_store.go +++ b/cli/config/credentials/file_store.go @@ -74,7 +74,10 @@ func ConvertToHostname(maybeURL string) string { if strings.Contains(stripped, "://") { u, err := url.Parse(stripped) if err == nil && u.Hostname() != "" { - return u.Hostname() + if u.Port() == "" { + return u.Hostname() + } + return u.Hostname() + ":" + u.Port() } } hostName, _, _ := strings.Cut(stripped, "/") diff --git a/cli/config/credentials/file_store_test.go b/cli/config/credentials/file_store_test.go index 74d63afcd6..436a3c8121 100644 --- a/cli/config/credentials/file_store_test.go +++ b/cli/config/credentials/file_store_test.go @@ -167,6 +167,23 @@ func TestConvertToHostname(t *testing.T) { input: "ftp://example.com", expected: "example.com", }, + // should support non-standard port in registry url + { + input: "example.com:6555", + expected: "example.com:6555", + }, + { + input: "http://example.com:6555", + expected: "example.com:6555", + }, + { + input: "https://example.com:6555", + expected: "example.com:6555", + }, + { + input: "https://example.com:6555/v2/", + expected: "example.com:6555", + }, } for _, tc := range tests { tc := tc