[FEATURE] Redis DB Index Selection (#653)
* [FEATURE] Redis DB Number Selection - Allow users to specify the DB number - This is so users who use their redis for multiple purposes can have clear demarcation between their data * revert: import order * Add default/example to config template with docs * Set DB Index property name to be more clearpull/657/head
parent
829757d3bc
commit
fc05b973ad
|
@ -223,6 +223,8 @@ session:
|
|||
port: 6379
|
||||
# This secret can also be set using the env variables AUTHELIA_SESSION_REDIS_PASSWORD
|
||||
password: authelia
|
||||
# This is the Redis DB Index https://redis.io/commands/select (sometimes referred to as database number, DB, etc).
|
||||
database_index: 0
|
||||
|
||||
# Configuration of the authentication regulation mechanism.
|
||||
#
|
||||
|
|
|
@ -5,6 +5,7 @@ type RedisSessionConfiguration struct {
|
|||
Host string `mapstructure:"host"`
|
||||
Port int64 `mapstructure:"port"`
|
||||
Password string `mapstructure:"password"`
|
||||
DatabaseIndex int `mapstructure:"database_index"`
|
||||
}
|
||||
|
||||
// SessionConfiguration represents the configuration related to user sessions.
|
||||
|
|
|
@ -46,6 +46,8 @@ func NewProviderConfig(configuration schema.SessionConfiguration) ProviderConfig
|
|||
Host: configuration.Redis.Host,
|
||||
Port: configuration.Redis.Port,
|
||||
Password: configuration.Redis.Password,
|
||||
// DbNumber is the fasthttp/session property for the Redis DB Index
|
||||
DbNumber: configuration.Redis.DatabaseIndex,
|
||||
PoolSize: 8,
|
||||
IdleTimeout: 300,
|
||||
KeyPrefix: "authelia-session",
|
||||
|
|
|
@ -54,4 +54,25 @@ func TestShouldCreateRedisSessionProvider(t *testing.T) {
|
|||
assert.Equal(t, "redis.example.com", pConfig.Host)
|
||||
assert.Equal(t, int64(6379), pConfig.Port)
|
||||
assert.Equal(t, "pass", pConfig.Password)
|
||||
// DbNumber is the fasthttp/session property for the Redis DB Index
|
||||
assert.Equal(t, 0, pConfig.DbNumber)
|
||||
}
|
||||
|
||||
func TestShouldSetDbNumber(t *testing.T) {
|
||||
configuration := schema.SessionConfiguration{}
|
||||
configuration.Domain = "example.com"
|
||||
configuration.Name = "my_session"
|
||||
configuration.Expiration = 40
|
||||
configuration.Redis = &schema.RedisSessionConfiguration{
|
||||
Host: "redis.example.com",
|
||||
Port: 6379,
|
||||
Password: "pass",
|
||||
DatabaseIndex: 5,
|
||||
}
|
||||
providerConfig := NewProviderConfig(configuration)
|
||||
assert.Equal(t, "redis", providerConfig.providerName)
|
||||
assert.IsType(t, &redis.Config{}, providerConfig.providerConfig)
|
||||
pConfig := providerConfig.providerConfig.(*redis.Config)
|
||||
// DbNumber is the fasthttp/session property for the Redis DB Index
|
||||
assert.Equal(t, 5, pConfig.DbNumber)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue