Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cli/config/credentials/file_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can expect IPv6 addresses, we should probably use netJoinHostPort() here;

return net.JoinHostPort(u.Hostname(), u.Port())

}
}
hostName, _, _ := strings.Cut(stripped, "/")
Expand Down
17 changes: 17 additions & 0 deletions cli/config/credentials/file_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ func TestConvertToHostname(t *testing.T) {
input: "ftp://example.com",
expected: "example.com",
},
// should support non-standard port in registry url
{
Comment on lines +170 to +171
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably add some test-cases here for IP-addresses

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
Expand Down