feat(inputs.rabbitmq): Add secretstore support for username and password (#13991)

This commit is contained in:
Yonathan Amir 2023-09-27 23:18:54 +03:00 committed by GitHub
parent 637b8f8721
commit 1f029cb127
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 10 deletions

View File

@ -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

View File

@ -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)