Merge branch 'main' of https://github.com/authorizerdev/authorizer
This commit is contained in:
commit
7a2dbea019
|
@ -3,6 +3,8 @@ package constants
|
||||||
var VERSION = "0.0.1"
|
var VERSION = "0.0.1"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// TestEnv is used for testing
|
||||||
|
TestEnv = "test"
|
||||||
// EnvKeyEnv key for env variable ENV
|
// EnvKeyEnv key for env variable ENV
|
||||||
EnvKeyEnv = "ENV"
|
EnvKeyEnv = "ENV"
|
||||||
// EnvKeyEnvPath key for cli arg variable ENV_PATH
|
// EnvKeyEnvPath key for cli arg variable ENV_PATH
|
||||||
|
|
|
@ -37,7 +37,7 @@ func SendMail(to []string, Subject, bodyMessage string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if envKey == "test" {
|
if envKey == constants.TestEnv {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
m := gomail.NewMessage()
|
m := gomail.NewMessage()
|
||||||
|
|
|
@ -3,6 +3,8 @@ package inmemory
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EnvStore struct to store the env variables
|
// EnvStore struct to store the env variables
|
||||||
|
@ -13,7 +15,7 @@ type EnvStore struct {
|
||||||
|
|
||||||
// UpdateEnvStore to update the whole env store object
|
// UpdateEnvStore to update the whole env store object
|
||||||
func (e *EnvStore) UpdateStore(store map[string]interface{}) {
|
func (e *EnvStore) UpdateStore(store map[string]interface{}) {
|
||||||
if os.Getenv("ENV") != "test" {
|
if os.Getenv("ENV") != constants.TestEnv {
|
||||||
e.mutex.Lock()
|
e.mutex.Lock()
|
||||||
defer e.mutex.Unlock()
|
defer e.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -26,26 +28,17 @@ func (e *EnvStore) UpdateStore(store map[string]interface{}) {
|
||||||
|
|
||||||
// GetStore returns the env store
|
// GetStore returns the env store
|
||||||
func (e *EnvStore) GetStore() map[string]interface{} {
|
func (e *EnvStore) GetStore() map[string]interface{} {
|
||||||
if os.Getenv("ENV") != "test" {
|
|
||||||
e.mutex.Lock()
|
|
||||||
defer e.mutex.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.store
|
return e.store
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the value of the key in evn store
|
// Get returns the value of the key in evn store
|
||||||
func (e *EnvStore) Get(key string) interface{} {
|
func (e *EnvStore) Get(key string) interface{} {
|
||||||
if os.Getenv("ENV") != "test" {
|
|
||||||
e.mutex.Lock()
|
|
||||||
defer e.mutex.Unlock()
|
|
||||||
}
|
|
||||||
return e.store[key]
|
return e.store[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set sets the value of the key in env store
|
// Set sets the value of the key in env store
|
||||||
func (e *EnvStore) Set(key string, value interface{}) {
|
func (e *EnvStore) Set(key string, value interface{}) {
|
||||||
if os.Getenv("ENV") != "test" {
|
if os.Getenv("ENV") != constants.TestEnv {
|
||||||
e.mutex.Lock()
|
e.mutex.Lock()
|
||||||
defer e.mutex.Unlock()
|
defer e.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ClearStore clears the in-memory store.
|
// ClearStore clears the in-memory store.
|
||||||
func (c *provider) ClearStore() error {
|
func (c *provider) ClearStore() error {
|
||||||
if os.Getenv("ENV") != "test" {
|
if os.Getenv("ENV") != constants.TestEnv {
|
||||||
c.mutex.Lock()
|
c.mutex.Lock()
|
||||||
defer c.mutex.Unlock()
|
defer c.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -19,10 +21,6 @@ func (c *provider) ClearStore() error {
|
||||||
|
|
||||||
// GetUserSessions returns all the user session token from the in-memory store.
|
// GetUserSessions returns all the user session token from the in-memory store.
|
||||||
func (c *provider) GetUserSessions(userId string) map[string]string {
|
func (c *provider) GetUserSessions(userId string) map[string]string {
|
||||||
if os.Getenv("ENV") != "test" {
|
|
||||||
c.mutex.Lock()
|
|
||||||
defer c.mutex.Unlock()
|
|
||||||
}
|
|
||||||
res := map[string]string{}
|
res := map[string]string{}
|
||||||
for k, v := range c.stateStore {
|
for k, v := range c.stateStore {
|
||||||
split := strings.Split(v, "@")
|
split := strings.Split(v, "@")
|
||||||
|
@ -36,7 +34,7 @@ func (c *provider) GetUserSessions(userId string) map[string]string {
|
||||||
|
|
||||||
// DeleteAllUserSession deletes all the user sessions from in-memory store.
|
// DeleteAllUserSession deletes all the user sessions from in-memory store.
|
||||||
func (c *provider) DeleteAllUserSession(userId string) error {
|
func (c *provider) DeleteAllUserSession(userId string) error {
|
||||||
if os.Getenv("ENV") != "test" {
|
if os.Getenv("ENV") != constants.TestEnv {
|
||||||
c.mutex.Lock()
|
c.mutex.Lock()
|
||||||
defer c.mutex.Unlock()
|
defer c.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -50,7 +48,7 @@ func (c *provider) DeleteAllUserSession(userId string) error {
|
||||||
|
|
||||||
// SetState sets the state in the in-memory store.
|
// SetState sets the state in the in-memory store.
|
||||||
func (c *provider) SetState(key, state string) error {
|
func (c *provider) SetState(key, state string) error {
|
||||||
if os.Getenv("ENV") != "test" {
|
if os.Getenv("ENV") != constants.TestEnv {
|
||||||
c.mutex.Lock()
|
c.mutex.Lock()
|
||||||
defer c.mutex.Unlock()
|
defer c.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -61,11 +59,6 @@ func (c *provider) SetState(key, state string) error {
|
||||||
|
|
||||||
// GetState gets the state from the in-memory store.
|
// GetState gets the state from the in-memory store.
|
||||||
func (c *provider) GetState(key string) (string, error) {
|
func (c *provider) GetState(key string) (string, error) {
|
||||||
if os.Getenv("ENV") != "test" {
|
|
||||||
c.mutex.Lock()
|
|
||||||
defer c.mutex.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
state := ""
|
state := ""
|
||||||
if stateVal, ok := c.stateStore[key]; ok {
|
if stateVal, ok := c.stateStore[key]; ok {
|
||||||
state = stateVal
|
state = stateVal
|
||||||
|
@ -76,7 +69,7 @@ func (c *provider) GetState(key string) (string, error) {
|
||||||
|
|
||||||
// RemoveState removes the state from the in-memory store.
|
// RemoveState removes the state from the in-memory store.
|
||||||
func (c *provider) RemoveState(key string) error {
|
func (c *provider) RemoveState(key string) error {
|
||||||
if os.Getenv("ENV") != "test" {
|
if os.Getenv("ENV") != constants.TestEnv {
|
||||||
c.mutex.Lock()
|
c.mutex.Lock()
|
||||||
defer c.mutex.Unlock()
|
defer c.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user