Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teach netrc lookup to try the portless host, too #485

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 20 additions & 5 deletions httputil/httputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func tryFindNetrcFileCreds(host string) (string, error) {
if m == nil {
// if host is not found, we should proceed without providing any Authorization header,
// because remote host may not have auth at all.
log.Printf("Skipping basic authentication for %s because no credentials found in %s", host, file)
log.Printf("No credentials found for %s in %s", host, file)
return "", fmt.Errorf("could not find creds for %s in netrc %s", host, file)
}

Expand Down Expand Up @@ -195,10 +195,25 @@ func DownloadBinary(originURL, destDir, destFile string) (string, error) {
log.Printf("Downloading %s...", originURL)

var auth string = ""
t, err := tryFindNetrcFileCreds(u.Host)
if err == nil {
// successfully parsed netrc for given host
auth = t
// By convention, netrc "machine" entries aren't supposed to have ports
// on them, but u.Host will have a port if the user provided one. To
// preserve historic behavior, look for the entry with a port, before
// falling back to portless (if they're different)
hosts := []string{u.Host}
if h := u.Hostname(); h != u.Host {
hosts = append(hosts, h)
}

for _, host := range hosts {
t, err := tryFindNetrcFileCreds(host)
if err == nil {
// successfully parsed netrc for given host
auth = t
break
}
}
if auth == "" {
log.Printf("Skipping basic authentication, no credentials found")
}

resp, err := get(originURL, auth)
Expand Down