Skip to content

Commit b31505e

Browse files
committed
added deprecation to json for RECIPIENTS and BLOCKED_ENDOINTS
1 parent 9cea14f commit b31505e

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

utils/env/env.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package env
33
import (
44
"os"
55
"strconv"
6+
"strings"
67

78
middlewares "github.com/codeshelldev/secured-signal-api/internals/proxy/middlewares"
89
"github.com/codeshelldev/secured-signal-api/utils"
10+
"github.com/codeshelldev/secured-signal-api/utils/docker"
911
log "github.com/codeshelldev/secured-signal-api/utils/logger"
1012
)
1113

@@ -83,16 +85,17 @@ func Load() {
8385
apiToken = os.Getenv("API_TOKEN")
8486
}
8587

86-
blockedEndpointJSON := os.Getenv("BLOCKED_ENDPOINTS")
87-
recipientsJSON := os.Getenv("RECIPIENTS")
88+
blockedEndpointStrArray := os.Getenv("BLOCKED_ENDPOINTS")
89+
recipientsStrArray := os.Getenv("RECIPIENTS")
90+
8891
messageAliasesJSON := os.Getenv("MESSAGE_ALIASES")
8992
variablesJSON := os.Getenv("VARIABLES")
9093

9194
log.Info("Loaded Environment Variables")
9295

93-
apiTokens, err := utils.StringToArray(apiToken)
96+
apiTokens := utils.StringToArray(apiToken)
9497

95-
if err != nil {
98+
if apiTokens == nil {
9699
log.Warn("No API TOKEN provided this is NOT recommended")
97100

98101
log.Info("Disabling Security Features due to incomplete Congfiguration")
@@ -104,8 +107,17 @@ func Load() {
104107
ENV.API_TOKENS = apiTokens
105108
}
106109

107-
if blockedEndpointJSON != "" {
108-
ENV.BLOCKED_ENDPOINTS = utils.GetJson[[]string](blockedEndpointJSON)
110+
if blockedEndpointStrArray != "" {
111+
if strings.Contains(blockedEndpointStrArray, "[") || strings.Contains(blockedEndpointStrArray, "]") {
112+
//! Deprecated: JSON
113+
//TODO: Remove this in new Version
114+
115+
log.Error("Invalid Blocked Endpoints: ", "JSON instead of Comma seperated String")
116+
117+
docker.Exit(1)
118+
}
119+
120+
ENV.BLOCKED_ENDPOINTS = utils.StringToArray(blockedEndpointStrArray)
109121
}
110122

111123
if messageAliasesJSON != "" {
@@ -116,7 +128,16 @@ func Load() {
116128
ENV.VARIABLES = utils.GetJson[map[string]any](variablesJSON)
117129
}
118130

119-
if recipientsJSON != "" {
120-
ENV.VARIABLES["RECIPIENTS"] = utils.GetJson[[]string](recipientsJSON)
131+
if recipientsStrArray != "" {
132+
if strings.Contains(blockedEndpointStrArray, "[") || strings.Contains(blockedEndpointStrArray, "]") {
133+
//! Deprecated: JSON
134+
//TODO: Remove this in new Version
135+
136+
log.Error("Invalid Blocked Endpoints: ", "JSON instead of Comma seperated String")
137+
138+
docker.Exit(1)
139+
}
140+
141+
ENV.VARIABLES["RECIPIENTS"] = utils.StringToArray(recipientsStrArray)
121142
}
122143
}

0 commit comments

Comments
 (0)