feat(config): redis username and password flags overrides uri

This commit is contained in:
Trong Huu Nguyen
2023-10-12 08:21:34 +02:00
parent 555f87b42b
commit b910d3e65a
2 changed files with 14 additions and 8 deletions

View File

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

View File

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