mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
[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 clear
This commit is contained in:
parent
829757d3bc
commit
fc05b973ad
|
@ -223,6 +223,8 @@ session:
|
||||||
port: 6379
|
port: 6379
|
||||||
# This secret can also be set using the env variables AUTHELIA_SESSION_REDIS_PASSWORD
|
# This secret can also be set using the env variables AUTHELIA_SESSION_REDIS_PASSWORD
|
||||||
password: authelia
|
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.
|
# Configuration of the authentication regulation mechanism.
|
||||||
#
|
#
|
||||||
|
|
|
@ -5,6 +5,7 @@ type RedisSessionConfiguration struct {
|
||||||
Host string `mapstructure:"host"`
|
Host string `mapstructure:"host"`
|
||||||
Port int64 `mapstructure:"port"`
|
Port int64 `mapstructure:"port"`
|
||||||
Password string `mapstructure:"password"`
|
Password string `mapstructure:"password"`
|
||||||
|
DatabaseIndex int `mapstructure:"database_index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SessionConfiguration represents the configuration related to user sessions.
|
// SessionConfiguration represents the configuration related to user sessions.
|
||||||
|
|
|
@ -46,6 +46,8 @@ func NewProviderConfig(configuration schema.SessionConfiguration) ProviderConfig
|
||||||
Host: configuration.Redis.Host,
|
Host: configuration.Redis.Host,
|
||||||
Port: configuration.Redis.Port,
|
Port: configuration.Redis.Port,
|
||||||
Password: configuration.Redis.Password,
|
Password: configuration.Redis.Password,
|
||||||
|
// DbNumber is the fasthttp/session property for the Redis DB Index
|
||||||
|
DbNumber: configuration.Redis.DatabaseIndex,
|
||||||
PoolSize: 8,
|
PoolSize: 8,
|
||||||
IdleTimeout: 300,
|
IdleTimeout: 300,
|
||||||
KeyPrefix: "authelia-session",
|
KeyPrefix: "authelia-session",
|
||||||
|
|
|
@ -54,4 +54,25 @@ func TestShouldCreateRedisSessionProvider(t *testing.T) {
|
||||||
assert.Equal(t, "redis.example.com", pConfig.Host)
|
assert.Equal(t, "redis.example.com", pConfig.Host)
|
||||||
assert.Equal(t, int64(6379), pConfig.Port)
|
assert.Equal(t, int64(6379), pConfig.Port)
|
||||||
assert.Equal(t, "pass", pConfig.Password)
|
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
Block a user