Skip to content

Commit 7a2dbea

Browse files
committed
2 parents dff5009 + aff9d3a commit 7a2dbea

File tree

4 files changed

+13
-25
lines changed

4 files changed

+13
-25
lines changed

server/constants/env.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package constants
33
var VERSION = "0.0.1"
44

55
const (
6+
// TestEnv is used for testing
7+
TestEnv = "test"
68
// EnvKeyEnv key for env variable ENV
79
EnvKeyEnv = "ENV"
810
// EnvKeyEnvPath key for cli arg variable ENV_PATH

server/email/email.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func SendMail(to []string, Subject, bodyMessage string) error {
3737
if err != nil {
3838
return err
3939
}
40-
if envKey == "test" {
40+
if envKey == constants.TestEnv {
4141
return nil
4242
}
4343
m := gomail.NewMessage()

server/memorystore/providers/inmemory/envstore.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package inmemory
33
import (
44
"os"
55
"sync"
6+
7+
"github.com/authorizerdev/authorizer/server/constants"
68
)
79

810
// EnvStore struct to store the env variables
@@ -13,7 +15,7 @@ type EnvStore struct {
1315

1416
// UpdateEnvStore to update the whole env store object
1517
func (e *EnvStore) UpdateStore(store map[string]interface{}) {
16-
if os.Getenv("ENV") != "test" {
18+
if os.Getenv("ENV") != constants.TestEnv {
1719
e.mutex.Lock()
1820
defer e.mutex.Unlock()
1921
}
@@ -26,26 +28,17 @@ func (e *EnvStore) UpdateStore(store map[string]interface{}) {
2628

2729
// GetStore returns the env store
2830
func (e *EnvStore) GetStore() map[string]interface{} {
29-
if os.Getenv("ENV") != "test" {
30-
e.mutex.Lock()
31-
defer e.mutex.Unlock()
32-
}
33-
3431
return e.store
3532
}
3633

3734
// Get returns the value of the key in evn store
3835
func (e *EnvStore) Get(key string) interface{} {
39-
if os.Getenv("ENV") != "test" {
40-
e.mutex.Lock()
41-
defer e.mutex.Unlock()
42-
}
4336
return e.store[key]
4437
}
4538

4639
// Set sets the value of the key in env store
4740
func (e *EnvStore) Set(key string, value interface{}) {
48-
if os.Getenv("ENV") != "test" {
41+
if os.Getenv("ENV") != constants.TestEnv {
4942
e.mutex.Lock()
5043
defer e.mutex.Unlock()
5144
}

server/memorystore/providers/inmemory/store.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import (
44
"fmt"
55
"os"
66
"strings"
7+
8+
"github.com/authorizerdev/authorizer/server/constants"
79
)
810

911
// ClearStore clears the in-memory store.
1012
func (c *provider) ClearStore() error {
11-
if os.Getenv("ENV") != "test" {
13+
if os.Getenv("ENV") != constants.TestEnv {
1214
c.mutex.Lock()
1315
defer c.mutex.Unlock()
1416
}
@@ -19,10 +21,6 @@ func (c *provider) ClearStore() error {
1921

2022
// GetUserSessions returns all the user session token from the in-memory store.
2123
func (c *provider) GetUserSessions(userId string) map[string]string {
22-
if os.Getenv("ENV") != "test" {
23-
c.mutex.Lock()
24-
defer c.mutex.Unlock()
25-
}
2624
res := map[string]string{}
2725
for k, v := range c.stateStore {
2826
split := strings.Split(v, "@")
@@ -36,7 +34,7 @@ func (c *provider) GetUserSessions(userId string) map[string]string {
3634

3735
// DeleteAllUserSession deletes all the user sessions from in-memory store.
3836
func (c *provider) DeleteAllUserSession(userId string) error {
39-
if os.Getenv("ENV") != "test" {
37+
if os.Getenv("ENV") != constants.TestEnv {
4038
c.mutex.Lock()
4139
defer c.mutex.Unlock()
4240
}
@@ -50,7 +48,7 @@ func (c *provider) DeleteAllUserSession(userId string) error {
5048

5149
// SetState sets the state in the in-memory store.
5250
func (c *provider) SetState(key, state string) error {
53-
if os.Getenv("ENV") != "test" {
51+
if os.Getenv("ENV") != constants.TestEnv {
5452
c.mutex.Lock()
5553
defer c.mutex.Unlock()
5654
}
@@ -61,11 +59,6 @@ func (c *provider) SetState(key, state string) error {
6159

6260
// GetState gets the state from the in-memory store.
6361
func (c *provider) GetState(key string) (string, error) {
64-
if os.Getenv("ENV") != "test" {
65-
c.mutex.Lock()
66-
defer c.mutex.Unlock()
67-
}
68-
6962
state := ""
7063
if stateVal, ok := c.stateStore[key]; ok {
7164
state = stateVal
@@ -76,7 +69,7 @@ func (c *provider) GetState(key string) (string, error) {
7669

7770
// RemoveState removes the state from the in-memory store.
7871
func (c *provider) RemoveState(key string) error {
79-
if os.Getenv("ENV") != "test" {
72+
if os.Getenv("ENV") != constants.TestEnv {
8073
c.mutex.Lock()
8174
defer c.mutex.Unlock()
8275
}

0 commit comments

Comments
 (0)