Add reading bearer token from a file to http input (#7304)
This commit is contained in:
parent
0fa92a686e
commit
27f09758ba
|
@ -26,6 +26,10 @@ The HTTP input plugin collects metrics from one or more HTTP(S) endpoints. The
|
|||
## compress body or "identity" to apply no encoding.
|
||||
# content_encoding = "identity"
|
||||
|
||||
## Optional file with Bearer token
|
||||
## file content is added as an Authorization header
|
||||
# bearer_token = "/path/to/file"
|
||||
|
||||
## Optional HTTP Basic Auth Credentials
|
||||
# username = "username"
|
||||
# password = "pa$$word"
|
||||
|
|
|
@ -29,6 +29,9 @@ type HTTP struct {
|
|||
Password string `toml:"password"`
|
||||
tls.ClientConfig
|
||||
|
||||
// Absolute path to file with Bearer token
|
||||
BearerToken string `toml:"bearer_token"`
|
||||
|
||||
SuccessStatusCodes []int `toml:"success_status_codes"`
|
||||
|
||||
Timeout internal.Duration `toml:"timeout"`
|
||||
|
@ -52,6 +55,10 @@ var sampleConfig = `
|
|||
## Optional HTTP headers
|
||||
# headers = {"X-Special-Header" = "Special-Value"}
|
||||
|
||||
## Optional file with Bearer token
|
||||
## file content is added as an Authorization header
|
||||
# bearer_token = "/path/to/file"
|
||||
|
||||
## Optional HTTP Basic Auth Credentials
|
||||
# username = "username"
|
||||
# password = "pa$$word"
|
||||
|
@ -160,6 +167,15 @@ func (h *HTTP) gatherURL(
|
|||
return err
|
||||
}
|
||||
|
||||
if h.BearerToken != "" {
|
||||
token, err := ioutil.ReadFile(h.BearerToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bearer := "Bearer " + strings.Trim(string(token), "\n")
|
||||
request.Header.Set("Authorization", bearer)
|
||||
}
|
||||
|
||||
if h.ContentEncoding == "gzip" {
|
||||
request.Header.Set("Content-Encoding", "gzip")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue