fix: env saving
This commit is contained in:
@@ -15,9 +15,12 @@ type RedisClient interface {
|
||||
Del(ctx context.Context, keys ...string) *redis.IntCmd
|
||||
HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd
|
||||
HMGet(ctx context.Context, key string, fields ...string) *redis.SliceCmd
|
||||
HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd
|
||||
HGet(ctx context.Context, key, field string) *redis.StringCmd
|
||||
HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd
|
||||
Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
|
||||
Get(ctx context.Context, key string) *redis.StringCmd
|
||||
Scan(ctx context.Context, cursor uint64, match string, count int64) *redis.ScanCmd
|
||||
}
|
||||
|
||||
type provider struct {
|
||||
|
@@ -1,16 +1,18 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
// session store prefix
|
||||
sessionStorePrefix = "authorizer_session_"
|
||||
sessionStorePrefix = "authorizer_session:"
|
||||
// env store prefix
|
||||
envStorePrefix = "authorizer_env_"
|
||||
envStorePrefix = "authorizer_env"
|
||||
)
|
||||
|
||||
// ClearStore clears the redis store for authorizer related tokens
|
||||
@@ -94,9 +96,8 @@ func (c *provider) RemoveState(key string) error {
|
||||
// UpdateEnvStore to update the whole env store object
|
||||
func (c *provider) UpdateEnvStore(store map[string]interface{}) error {
|
||||
for key, value := range store {
|
||||
err := c.store.Set(c.ctx, envStorePrefix+key, value, 0).Err()
|
||||
err := c.store.HSet(c.ctx, envStorePrefix, key, value).Err()
|
||||
if err != nil {
|
||||
log.Debug("Error saving redis token: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -105,19 +106,28 @@ func (c *provider) UpdateEnvStore(store map[string]interface{}) error {
|
||||
|
||||
// GetEnvStore returns the whole env store object
|
||||
func (c *provider) GetEnvStore() (map[string]interface{}, error) {
|
||||
var res map[string]interface{}
|
||||
err := c.store.HGetAll(c.ctx, envStorePrefix+"*").Scan(res)
|
||||
res := make(map[string]interface{})
|
||||
data, err := c.store.HGetAll(c.ctx, envStorePrefix).Result()
|
||||
if err != nil {
|
||||
log.Debug("error getting token from redis store: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for key, value := range data {
|
||||
if key == constants.EnvKeyDisableBasicAuthentication || key == constants.EnvKeyDisableEmailVerification || key == constants.EnvKeyDisableLoginPage || key == constants.EnvKeyDisableMagicLinkLogin || key == constants.EnvKeyDisableRedisForEnv || key == constants.EnvKeyDisableSignUp {
|
||||
boolValue, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res[key] = boolValue
|
||||
} else {
|
||||
res[key] = value
|
||||
}
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// UpdateEnvVariable to update the particular env variable
|
||||
func (c *provider) UpdateEnvVariable(key string, value interface{}) error {
|
||||
err := c.store.Set(c.ctx, envStorePrefix+key, value, 0).Err()
|
||||
err := c.store.HSet(c.ctx, envStorePrefix, key, value).Err()
|
||||
if err != nil {
|
||||
log.Debug("Error saving redis token: ", err)
|
||||
return err
|
||||
@@ -128,10 +138,9 @@ func (c *provider) UpdateEnvVariable(key string, value interface{}) error {
|
||||
// GetStringStoreEnvVariable to get the string env variable from env store
|
||||
func (c *provider) GetStringStoreEnvVariable(key string) (string, error) {
|
||||
var res string
|
||||
err := c.store.Get(c.ctx, envStorePrefix+key).Scan(&res)
|
||||
err := c.store.HGet(c.ctx, envStorePrefix, key).Scan(&res)
|
||||
if err != nil {
|
||||
log.Debug("error getting token from redis store: ", err)
|
||||
return "", err
|
||||
return "", nil
|
||||
}
|
||||
|
||||
return res, nil
|
||||
@@ -140,10 +149,9 @@ func (c *provider) GetStringStoreEnvVariable(key string) (string, error) {
|
||||
// GetBoolStoreEnvVariable to get the bool env variable from env store
|
||||
func (c *provider) GetBoolStoreEnvVariable(key string) (bool, error) {
|
||||
var res bool
|
||||
err := c.store.Get(c.ctx, envStorePrefix+key).Scan(res)
|
||||
err := c.store.HGet(c.ctx, envStorePrefix, key).Scan(res)
|
||||
if err != nil {
|
||||
log.Debug("error getting token from redis store: ", err)
|
||||
return false, err
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
Reference in New Issue
Block a user