diff --git a/docs/configuration.md b/docs/configuration.md index d956730..269e267 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -32,10 +32,10 @@ The following flags are available: | `openid.well-known-url` | string | URI to the well-known OpenID Configuration metadata document. | | | `redis.address` | string | Address of the Redis instance (host:port). An empty value will use in-memory session storage. Does not override address set by `redis.uri`. | | | `redis.connection-idle-timeout` | int | Idle timeout for Redis connections, in seconds. If non-zero, the value should be less than the client timeout configured at the Redis server. A value of -1 disables timeout. If zero, the default value from go-redis is used (30 minutes). Overrides options set by `redis.uri`. | `0` | -| `redis.password` | string | Password for Redis. Does not override password set by `redis.uri`. | | +| `redis.password` | string | Password for Redis. Overrides password set by `redis.uri`. | | | `redis.tls` | boolean | Whether or not to use TLS for connecting to Redis. Does not override TLS config set by `redis.uri`. | `true` | | `redis.uri` | string | Redis URI string. Prefer using this. An empty value will fall back to `redis-address`. | | -| `redis.username` | string | Username for Redis. Does not override username set by `redis.uri`. | | +| `redis.username` | string | Username for Redis. Overrides username set by `redis.uri`. | | | `session.inactivity` | boolean | Automatically expire user sessions if they have not refreshed their tokens within a given duration. | `false` | | `session.inactivity-timeout` | duration | Inactivity timeout for user sessions. | `30m` | | `session.max-lifetime` | duration | Max lifetime for user sessions. | `10h` | diff --git a/pkg/config/config.go b/pkg/config/config.go index e1cdbd2..84ba117 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -74,10 +74,8 @@ type Redis struct { func (r *Redis) Client() (*redis.Client, error) { opts := &redis.Options{ - Network: "tcp", - Addr: r.Address, - Username: r.Username, - Password: r.Password, + Network: "tcp", + Addr: r.Address, } if r.TLS { @@ -96,6 +94,14 @@ func (r *Redis) Client() (*redis.Client, error) { opts.MinIdleConns = 1 opts.MaxRetries = 5 + if r.Username != "" { + opts.Username = r.Username + } + + if r.Password != "" { + opts.Password = r.Password + } + if r.ConnectionIdleTimeout > 0 { opts.ConnMaxIdleTime = time.Duration(r.ConnectionIdleTimeout) * time.Second } else if r.ConnectionIdleTimeout == -1 { @@ -222,9 +228,9 @@ func Initialize() (*Config, error) { flag.String(RedisURI, "", "Redis URI string. Prefer using this. An empty value will fall back to 'redis-address'.") flag.String(RedisAddress, "", "Address of the Redis instance (host:port). An empty value will use in-memory session storage. Does not override address set by 'redis.uri'.") - flag.String(RedisPassword, "", "Password for Redis. Does not override password set by 'redis.uri'.") + flag.String(RedisPassword, "", "Password for Redis. Overrides password set by 'redis.uri'.") flag.Bool(RedisTLS, true, "Whether or not to use TLS for connecting to Redis. Does not override TLS config set by 'redis.uri'.") - flag.String(RedisUsername, "", "Username for Redis. Does not override username set by 'redis.uri'.") + flag.String(RedisUsername, "", "Username for Redis. Overrides username set by 'redis.uri'.") flag.Int(RedisConnectionIdleTimeout, 0, "Idle timeout for Redis connections, in seconds. If non-zero, the value should be less than the client timeout configured at the Redis server. A value of -1 disables timeout. If zero, the default value from go-redis is used (30 minutes). Overrides options set by 'redis.uri'.") flag.Bool(SessionInactivity, false, "Automatically expire user sessions if they have not refreshed their tokens within a given duration.")