feat(inputs.rabbitmq): Add secretstore support for username and password (#13991)
This commit is contained in:
parent
637b8f8721
commit
1f029cb127
|
|
@ -17,6 +17,15 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||||
|
|
||||||
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
|
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
|
||||||
|
|
||||||
|
## Secret-store support
|
||||||
|
|
||||||
|
This plugin supports secrets from secret-stores for the `username` and
|
||||||
|
`password` option.
|
||||||
|
See the [secret-store documentation][SECRETSTORE] for more details on how
|
||||||
|
to use them.
|
||||||
|
|
||||||
|
[SECRETSTORE]: ../../../docs/CONFIGURATION.md#secret-store-secrets
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
```toml @sample.conf
|
```toml @sample.conf
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,10 @@ const DefaultClientTimeout = 4
|
||||||
// RabbitMQ defines the configuration necessary for gathering metrics,
|
// RabbitMQ defines the configuration necessary for gathering metrics,
|
||||||
// see the sample config for further details
|
// see the sample config for further details
|
||||||
type RabbitMQ struct {
|
type RabbitMQ struct {
|
||||||
URL string `toml:"url"`
|
URL string `toml:"url"`
|
||||||
Name string `toml:"name" deprecated:"1.3.0;use 'tags' instead"`
|
Name string `toml:"name" deprecated:"1.3.0;use 'tags' instead"`
|
||||||
Username string `toml:"username"`
|
Username config.Secret `toml:"username"`
|
||||||
Password string `toml:"password"`
|
Password config.Secret `toml:"password"`
|
||||||
tls.ClientConfig
|
tls.ClientConfig
|
||||||
|
|
||||||
ResponseHeaderTimeout config.Duration `toml:"header_timeout"`
|
ResponseHeaderTimeout config.Duration `toml:"header_timeout"`
|
||||||
|
|
@ -350,14 +350,24 @@ func (r *RabbitMQ) requestEndpoint(u string) ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
username := r.Username
|
username := DefaultUsername
|
||||||
if username == "" {
|
if !r.Username.Empty() {
|
||||||
username = DefaultUsername
|
usernameSecret, err := r.Username.Get()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer usernameSecret.Destroy()
|
||||||
|
username = usernameSecret.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
password := r.Password
|
password := DefaultPassword
|
||||||
if password == "" {
|
if !r.Password.Empty() {
|
||||||
password = DefaultPassword
|
passwordSecret, err := r.Password.Get()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer passwordSecret.Destroy()
|
||||||
|
password = passwordSecret.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
req.SetBasicAuth(username, password)
|
req.SetBasicAuth(username, password)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue