feat(common.cookie): Allow usage of secrets for header (#15640)
Co-authored-by: Josh Powers <powersj@fastmail.com>
This commit is contained in:
parent
fbac735052
commit
9cb121c76a
|
|
@ -20,7 +20,7 @@ type CookieAuthConfig struct {
|
||||||
URL string `toml:"cookie_auth_url"`
|
URL string `toml:"cookie_auth_url"`
|
||||||
Method string `toml:"cookie_auth_method"`
|
Method string `toml:"cookie_auth_method"`
|
||||||
|
|
||||||
Headers map[string]string `toml:"cookie_auth_headers"`
|
Headers map[string]*config.Secret `toml:"cookie_auth_headers"`
|
||||||
|
|
||||||
// HTTP Basic Auth Credentials
|
// HTTP Basic Auth Credentials
|
||||||
Username string `toml:"cookie_auth_username"`
|
Username string `toml:"cookie_auth_username"`
|
||||||
|
|
@ -98,11 +98,19 @@ func (c *CookieAuthConfig) auth() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range c.Headers {
|
for k, v := range c.Headers {
|
||||||
if strings.EqualFold(k, "host") {
|
secret, err := v.Get()
|
||||||
req.Host = v
|
if err != nil {
|
||||||
} else {
|
return err
|
||||||
req.Header.Add(k, v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
headerVal := secret.String()
|
||||||
|
if strings.EqualFold(k, "host") {
|
||||||
|
req.Host = headerVal
|
||||||
|
} else {
|
||||||
|
req.Header.Add(k, headerVal)
|
||||||
|
}
|
||||||
|
|
||||||
|
secret.Destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := c.client.Do(req)
|
resp, err := c.client.Do(req)
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ var fakeCookie = &http.Cookie{
|
||||||
Value: "this is an auth cookie",
|
Value: "this is an auth cookie",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var reqHeaderValSecret = config.NewSecret([]byte(reqHeaderVal))
|
||||||
|
|
||||||
type fakeServer struct {
|
type fakeServer struct {
|
||||||
*httptest.Server
|
*httptest.Server
|
||||||
*int32
|
*int32
|
||||||
|
|
@ -123,7 +125,7 @@ func TestAuthConfig_Start(t *testing.T) {
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
Body string
|
Body string
|
||||||
Headers map[string]string
|
Headers map[string]*config.Secret
|
||||||
}
|
}
|
||||||
type args struct {
|
type args struct {
|
||||||
renewal time.Duration
|
renewal time.Duration
|
||||||
|
|
@ -157,7 +159,7 @@ func TestAuthConfig_Start(t *testing.T) {
|
||||||
endpoint: authEndpointWithHeader,
|
endpoint: authEndpointWithHeader,
|
||||||
},
|
},
|
||||||
fields: fields{
|
fields: fields{
|
||||||
Headers: map[string]string{reqHeaderKey: reqHeaderVal},
|
Headers: map[string]*config.Secret{reqHeaderKey: &reqHeaderValSecret},
|
||||||
},
|
},
|
||||||
firstAuthCount: 1,
|
firstAuthCount: 1,
|
||||||
lastAuthCount: 3,
|
lastAuthCount: 3,
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||||
## Secret-store support
|
## Secret-store support
|
||||||
|
|
||||||
This plugin supports secrets from secret-stores for the `username`, `password`,
|
This plugin supports secrets from secret-stores for the `username`, `password`,
|
||||||
`token` and `headers` option.
|
`token`, `headers`, and `cookie_auth_headers` option.
|
||||||
See the [secret-store documentation][SECRETSTORE] for more details on how
|
See the [secret-store documentation][SECRETSTORE] for more details on how
|
||||||
to use them.
|
to use them.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||||
## Secret-store support
|
## Secret-store support
|
||||||
|
|
||||||
This plugin supports secrets from secret-stores for the `username`, `password`
|
This plugin supports secrets from secret-stores for the `username`, `password`
|
||||||
and `headers` option.
|
`headers`, and `cookie_auth_headers` option.
|
||||||
See the [secret-store documentation][SECRETSTORE] for more details on how
|
See the [secret-store documentation][SECRETSTORE] for more details on how
|
||||||
to use them.
|
to use them.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue