Skip to content

Commit 87fa4f2

Browse files
authored
Merge pull request #52 from Icinga/redis-username-config
redis: Configurable Username
2 parents 64c2bc4 + 98575ec commit 87fa4f2

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

redis/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func NewClientFromConfig(c *Config, logger *logging.Logger) (*Client, error) {
5252

5353
options := &redis.Options{
5454
Dialer: dialWithLogging(dialer, logger),
55+
Username: c.Username,
5556
Password: c.Password,
5657
DB: c.Database,
5758
ReadTimeout: c.Options.Timeout,

redis/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func (o *Options) Validate() error {
4444
type Config struct {
4545
Host string `yaml:"host"`
4646
Port int `yaml:"port"`
47+
Username string `yaml:"username"`
4748
Password string `yaml:"password"`
4849
Database int `yaml:"database" default:"0"`
4950
TlsOptions config.TLS `yaml:",inline"`
@@ -56,5 +57,9 @@ func (r *Config) Validate() error {
5657
return errors.New("Redis host missing")
5758
}
5859

60+
if r.Username != "" && r.Password == "" {
61+
return errors.New("Redis password must be set, if username is provided")
62+
}
63+
5964
return r.Options.Validate()
6065
}

0 commit comments

Comments
 (0)