Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

parse credentials without scheme #2248

Merged
merged 1 commit into from
Jul 11, 2019
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
23 changes: 12 additions & 11 deletions registry/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,29 @@ func ParseCredentials(from string, b []byte) (Credentials, error) {
return Credentials{}, err
}

if host == "http://" || host == "https://" {
return Credentials{}, errors.New("Empty registry auth url")
}

// Some users were passing in credentials in the form of
// http://docker.io and http://docker.io/v1/, etc.
// So strip everything down to the host.
// Also, the registry might be local and on a different port.
// So we need to check for that because url.Parse won't parse the ip:port format very well.
u, err := url.Parse(host)
if err != nil {
return Credentials{}, err
}
if u.Host == "" && u.Path == "" && !strings.Contains(host, ":") || host == "http://" || host == "https://" {
return Credentials{}, errors.New("Empty registry auth url")
}
if u.Host == "" { // If there's no https:// prefix, it won't parse the host.

// if anything went wrong try to prepend https://
if err != nil || u.Host == "" {
u, err = url.Parse(fmt.Sprintf("https://%s/", host))
if err != nil {
return Credentials{}, err
}
// If the host is still empty, then there's probably a rogue /
if u.Host == "" {
return Credentials{}, errors.New("Invalid registry auth url. Must be a valid http address (e.g. https://gcr.io/v1/)")
}
}

if u.Host == "" { // If host is still empty the url must be broken.
return Credentials{}, errors.New("Invalid registry auth url. Must be a valid http address (e.g. https://gcr.io/v1/)")
}

host = u.Host

creds.registry = host
Expand Down
4 changes: 4 additions & 0 deletions registry/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func TestRemoteFactory_ParseHost(t *testing.T) {
host: "localhost:5000/v2/",
imagePrefix: "localhost:5000",
},
{
host: "192.168.99.100:5000",
imagePrefix: "192.168.99.100:5000",
},
{
host: "https://192.168.99.100:5000/v2",
imagePrefix: "192.168.99.100:5000",
Expand Down