This repository was archived by the owner on Mar 18, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,9 @@ type Config struct {
4141 // Password is the Password for the Basic Auth.
4242 Password null.String `json:"password"`
4343
44+ // BearerToken if set is the token used for the `Authorization` header.
45+ BearerToken null.String `json:"bearerToken"`
46+
4447 // PushInterval defines the time between flushes. The Output will wait the set time
4548 // before push a new set of time series to the endpoint.
4649 PushInterval types.NullDuration `json:"pushInterval"`
@@ -95,6 +98,14 @@ func (conf Config) RemoteConfig() (*remote.HTTPConfig, error) {
9598 hc .Headers .Add (k , v )
9699 }
97100 }
101+
102+ if conf .BearerToken .String != "" {
103+ if hc .Headers == nil {
104+ hc .Headers = make (http.Header )
105+ }
106+ hc .Headers .Set ("Authorization" , "Bearer " + conf .BearerToken .String )
107+ }
108+
98109 return & hc , nil
99110}
100111
Original file line number Diff line number Diff line change @@ -61,11 +61,15 @@ func TestConfigRemoteConfig(t *testing.T) {
6161 Password : null .StringFrom ("mypass" ),
6262 Headers : map [string ]string {
6363 "X-MYCUSTOM-HEADER" : "val1" ,
64+ // it asserts that Authz header is overwritten if the token is set
65+ "Authorization" : "pre-set-token" ,
6466 },
67+ BearerToken : null .StringFrom ("my-fake-token" ),
6568 }
6669
6770 headers := http.Header {}
6871 headers .Set ("X-MYCUSTOM-HEADER" , "val1" )
72+ headers .Set ("Authorization" , "Bearer my-fake-token" )
6973 exprcc := & remote.HTTPConfig {
7074 Timeout : 5 * time .Second ,
7175 TLSConfig : & tls.Config {
You can’t perform that action at this time.
0 commit comments