fix: update store method till handlers
This commit is contained in:
41
server/memorystore/providers/inmemory/envstore.go
Normal file
41
server/memorystore/providers/inmemory/envstore.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package inmemory
|
||||
|
||||
import "sync"
|
||||
|
||||
// EnvStore struct to store the env variables
|
||||
type EnvStore struct {
|
||||
mutex sync.Mutex
|
||||
store map[string]interface{}
|
||||
}
|
||||
|
||||
// UpdateEnvStore to update the whole env store object
|
||||
func (e *EnvStore) UpdateStore(store map[string]interface{}) {
|
||||
e.mutex.Lock()
|
||||
defer e.mutex.Unlock()
|
||||
// just override the keys + new keys
|
||||
|
||||
for key, value := range store {
|
||||
e.store[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
// GetStore returns the env store
|
||||
func (e *EnvStore) GetStore() map[string]interface{} {
|
||||
e.mutex.Lock()
|
||||
defer e.mutex.Unlock()
|
||||
return e.store
|
||||
}
|
||||
|
||||
// Get returns the value of the key in evn store
|
||||
func (s *EnvStore) Get(key string) interface{} {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
return s.store[key]
|
||||
}
|
||||
|
||||
// Set sets the value of the key in env store
|
||||
func (s *EnvStore) Set(key string, value interface{}) {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
s.store[key] = value
|
||||
}
|
@@ -1,11 +1,14 @@
|
||||
package inmemory
|
||||
|
||||
import "sync"
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
mutex sync.Mutex
|
||||
sessionStore map[string]map[string]string
|
||||
stateStore map[string]string
|
||||
envStore *EnvStore
|
||||
}
|
||||
|
||||
// NewInMemoryStore returns a new in-memory store.
|
||||
@@ -14,5 +17,9 @@ func NewInMemoryProvider() (*provider, error) {
|
||||
mutex: sync.Mutex{},
|
||||
sessionStore: map[string]map[string]string{},
|
||||
stateStore: map[string]string{},
|
||||
envStore: &EnvStore{
|
||||
mutex: sync.Mutex{},
|
||||
store: map[string]interface{}{},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
@@ -1,6 +1,10 @@
|
||||
package inmemory
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/utils"
|
||||
)
|
||||
|
||||
// ClearStore clears the in-memory store.
|
||||
func (c *provider) ClearStore() error {
|
||||
@@ -42,14 +46,13 @@ func (c *provider) DeleteAllUserSession(userId string) error {
|
||||
func (c *provider) SetState(key, state string) error {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
|
||||
c.stateStore[key] = state
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetState gets the state from the in-memory store.
|
||||
func (c *provider) GetState(key string) string {
|
||||
func (c *provider) GetState(key string) (string, error) {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
|
||||
@@ -58,15 +61,50 @@ func (c *provider) GetState(key string) string {
|
||||
state = stateVal
|
||||
}
|
||||
|
||||
return state
|
||||
return state, nil
|
||||
}
|
||||
|
||||
// RemoveState removes the state from the in-memory store.
|
||||
func (c *provider) RemoveState(key string) error {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
|
||||
delete(c.stateStore, key)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateEnvStore to update the whole env store object
|
||||
func (c *provider) UpdateEnvStore(store map[string]interface{}) error {
|
||||
c.envStore.UpdateStore(store)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetEnvStore returns the env store object
|
||||
func (c *provider) GetEnvStore() (map[string]interface{}, error) {
|
||||
return c.envStore.GetStore(), nil
|
||||
}
|
||||
|
||||
// UpdateEnvVariable to update the particular env variable
|
||||
func (c *provider) UpdateEnvVariable(key string, value interface{}) error {
|
||||
c.envStore.Set(key, value)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetStringStoreEnvVariable to get the env variable from string store object
|
||||
func (c *provider) GetStringStoreEnvVariable(key string) (string, error) {
|
||||
res := c.envStore.Get(key)
|
||||
return res.(string), nil
|
||||
}
|
||||
|
||||
// GetBoolStoreEnvVariable to get the env variable from bool store object
|
||||
func (c *provider) GetBoolStoreEnvVariable(key string) (bool, error) {
|
||||
res := c.envStore.Get(key)
|
||||
return res.(bool), nil
|
||||
}
|
||||
|
||||
// GetSliceStoreEnvVariable to get the env variable from slice store object
|
||||
func (c *provider) GetSliceStoreEnvVariable(key string) ([]string, error) {
|
||||
res := c.envStore.Get(key)
|
||||
resSlice := utils.ConvertInterfaceToStringSlice(res)
|
||||
return resSlice, nil
|
||||
}
|
Reference in New Issue
Block a user