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
|
||||
|
||||
## 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
|
||||
|
||||
```toml @sample.conf
|
||||
|
|
|
|||
|
|
@ -41,10 +41,10 @@ const DefaultClientTimeout = 4
|
|||
// RabbitMQ defines the configuration necessary for gathering metrics,
|
||||
// see the sample config for further details
|
||||
type RabbitMQ struct {
|
||||
URL string `toml:"url"`
|
||||
Name string `toml:"name" deprecated:"1.3.0;use 'tags' instead"`
|
||||
Username string `toml:"username"`
|
||||
Password string `toml:"password"`
|
||||
URL string `toml:"url"`
|
||||
Name string `toml:"name" deprecated:"1.3.0;use 'tags' instead"`
|
||||
Username config.Secret `toml:"username"`
|
||||
Password config.Secret `toml:"password"`
|
||||
tls.ClientConfig
|
||||
|
||||
ResponseHeaderTimeout config.Duration `toml:"header_timeout"`
|
||||
|
|
@ -350,14 +350,24 @@ func (r *RabbitMQ) requestEndpoint(u string) ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
username := r.Username
|
||||
if username == "" {
|
||||
username = DefaultUsername
|
||||
username := DefaultUsername
|
||||
if !r.Username.Empty() {
|
||||
usernameSecret, err := r.Username.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer usernameSecret.Destroy()
|
||||
username = usernameSecret.String()
|
||||
}
|
||||
|
||||
password := r.Password
|
||||
if password == "" {
|
||||
password = DefaultPassword
|
||||
password := DefaultPassword
|
||||
if !r.Password.Empty() {
|
||||
passwordSecret, err := r.Password.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer passwordSecret.Destroy()
|
||||
password = passwordSecret.String()
|
||||
}
|
||||
|
||||
req.SetBasicAuth(username, password)
|
||||
|
|
|
|||
Loading…
Reference in New Issue