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.
|
## compress body or "identity" to apply no encoding.
|
||||||
# content_encoding = "identity"
|
# 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
|
## Optional HTTP Basic Auth Credentials
|
||||||
# username = "username"
|
# username = "username"
|
||||||
# password = "pa$$word"
|
# password = "pa$$word"
|
||||||
|
|
|
@ -29,6 +29,9 @@ type HTTP struct {
|
||||||
Password string `toml:"password"`
|
Password string `toml:"password"`
|
||||||
tls.ClientConfig
|
tls.ClientConfig
|
||||||
|
|
||||||
|
// Absolute path to file with Bearer token
|
||||||
|
BearerToken string `toml:"bearer_token"`
|
||||||
|
|
||||||
SuccessStatusCodes []int `toml:"success_status_codes"`
|
SuccessStatusCodes []int `toml:"success_status_codes"`
|
||||||
|
|
||||||
Timeout internal.Duration `toml:"timeout"`
|
Timeout internal.Duration `toml:"timeout"`
|
||||||
|
@ -52,6 +55,10 @@ var sampleConfig = `
|
||||||
## Optional HTTP headers
|
## Optional HTTP headers
|
||||||
# headers = {"X-Special-Header" = "Special-Value"}
|
# 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
|
## Optional HTTP Basic Auth Credentials
|
||||||
# username = "username"
|
# username = "username"
|
||||||
# password = "pa$$word"
|
# password = "pa$$word"
|
||||||
|
@ -160,6 +167,15 @@ func (h *HTTP) gatherURL(
|
||||||
return err
|
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" {
|
if h.ContentEncoding == "gzip" {
|
||||||
request.Header.Set("Content-Encoding", "gzip")
|
request.Header.Set("Content-Encoding", "gzip")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue