-
Notifications
You must be signed in to change notification settings - Fork 386
Add Configuration variable to allow using custom Authorization header #710
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,8 @@ var ( | |
| DefaultTransport = http.DefaultTransport | ||
| // UserAgent is passed to every HTTP request as part of the 'User-Agent' header. | ||
| UserAgent = "Bazelisk" | ||
| // AuthHeader is optionally set to a value that is passed as part of the 'Authorization' header in HTTP requests. | ||
| AuthHeader = "" | ||
| linkPattern = regexp.MustCompile(`<(.*?)>; rel="(\w+)"`) | ||
|
|
||
| // RetryClock is used for waiting between HTTP request retries. | ||
|
|
@@ -213,10 +215,16 @@ func DownloadBinary(originURL, destDir, destFile string, config config.Config) ( | |
| log.Printf("Downloading %s...", originURL) | ||
|
|
||
| var auth string = "" | ||
| t, err := tryFindNetrcFileCreds(u.Host) | ||
| if err == nil { | ||
| // successfully parsed netrc for given host | ||
| auth = t | ||
| if AuthHeader != "" { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should raise an error if both AuthHeader is set and a .netrc file exists.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope,
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello @fweikert |
||
| // If AuthHeader is set, use it as the Authorization header. | ||
| log.Printf("Authorization header is set using BAZELISK_AUTH_HEADER, using it for %s", u.Host) | ||
Lan-Hekary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| auth = AuthHeader | ||
| } else { | ||
| t, err := tryFindNetrcFileCreds(u.Host) | ||
| if err == nil { | ||
| // successfully parsed netrc for given host | ||
| auth = t | ||
| } | ||
| } | ||
|
|
||
| resp, err := get(originURL, auth) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get() returns an empty string if missing, so you could just write
return config.Get("BAZELISK_AUTH_HEADER")