Skip to content

Commit

Permalink
Merge pull request #52 from Icinga/redis-username-config
Browse files Browse the repository at this point in the history
redis: Configurable Username
  • Loading branch information
julianbrost authored Aug 2, 2024
2 parents 64c2bc4 + 98575ec commit 87fa4f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions redis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func NewClientFromConfig(c *Config, logger *logging.Logger) (*Client, error) {

options := &redis.Options{
Dialer: dialWithLogging(dialer, logger),
Username: c.Username,
Password: c.Password,
DB: c.Database,
ReadTimeout: c.Options.Timeout,
Expand Down
5 changes: 5 additions & 0 deletions redis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (o *Options) Validate() error {
type Config struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Database int `yaml:"database" default:"0"`
TlsOptions config.TLS `yaml:",inline"`
Expand All @@ -56,5 +57,9 @@ func (r *Config) Validate() error {
return errors.New("Redis host missing")
}

if r.Username != "" && r.Password == "" {
return errors.New("Redis password must be set, if username is provided")
}

return r.Options.Validate()
}

0 comments on commit 87fa4f2

Please sign in to comment.