Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions plugins/inputs/rabbitmq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 20 additions & 10 deletions plugins/inputs/rabbitmq/rabbitmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
Expand Down