Add auth header only when env var is set (#6469)

This commit is contained in:
David McKay 2019-09-30 16:55:47 -07:00 committed by Daniel Nelson
parent d75b5e5e10
commit 367dee791a
1 changed files with 4 additions and 3 deletions

View File

@ -841,13 +841,14 @@ func loadConfig(config string) ([]byte, error) {
}
func fetchConfig(u *url.URL) ([]byte, error) {
v := os.Getenv("INFLUX_TOKEN")
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return nil, err
}
req.Header.Add("Authorization", "Token "+v)
if v, exists := os.LookupEnv("INFLUX_TOKEN"); exists {
req.Header.Add("Authorization", "Token "+v)
}
req.Header.Add("Accept", "application/toml")
resp, err := http.DefaultClient.Do(req)
if err != nil {