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

Commit

Permalink
Merge pull request #2248 from fnmeissner/parse-credentials-without-sc…
Browse files Browse the repository at this point in the history
…heme

parse credentials without scheme
  • Loading branch information
squaremo committed Jul 25, 2019
1 parent 9d0cce3 commit 411c8bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
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

0 comments on commit 411c8bc

Please sign in to comment.