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 {
41
41
// Password is the Password for the Basic Auth.
42
42
Password null.String `json:"password"`
43
43
44
+ // BearerToken if set is the token used for the `Authorization` header.
45
+ BearerToken null.String `json:"bearerToken"`
46
+
44
47
// PushInterval defines the time between flushes. The Output will wait the set time
45
48
// before push a new set of time series to the endpoint.
46
49
PushInterval types.NullDuration `json:"pushInterval"`
@@ -95,6 +98,14 @@ func (conf Config) RemoteConfig() (*remote.HTTPConfig, error) {
95
98
hc .Headers .Add (k , v )
96
99
}
97
100
}
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
+
98
109
return & hc , nil
99
110
}
100
111
Original file line number Diff line number Diff line change @@ -61,11 +61,15 @@ func TestConfigRemoteConfig(t *testing.T) {
61
61
Password : null .StringFrom ("mypass" ),
62
62
Headers : map [string ]string {
63
63
"X-MYCUSTOM-HEADER" : "val1" ,
64
+ // it asserts that Authz header is overwritten if the token is set
65
+ "Authorization" : "pre-set-token" ,
64
66
},
67
+ BearerToken : null .StringFrom ("my-fake-token" ),
65
68
}
66
69
67
70
headers := http.Header {}
68
71
headers .Set ("X-MYCUSTOM-HEADER" , "val1" )
72
+ headers .Set ("Authorization" , "Bearer my-fake-token" )
69
73
exprcc := & remote.HTTPConfig {
70
74
Timeout : 5 * time .Second ,
71
75
TLSConfig : & tls.Config {
You can’t perform that action at this time.
0 commit comments