11package env
22
33import (
4- "encoding/json"
54 "os"
65
76 middlewares "github.com/codeshelldev/secured-signal-api/internals/proxy/middlewares"
7+ "github.com/codeshelldev/secured-signal-api/utils"
88 log "github.com/codeshelldev/secured-signal-api/utils/logger"
99)
1010
1111type ENV_ struct {
1212 PORT string
1313 API_URL string
14- API_TOKEN string
14+ API_TOKENS [] string
1515 BLOCKED_ENDPOINTS []string
1616 VARIABLES map [string ]any
1717 MESSAGE_ALIASES []middlewares.MessageAlias
@@ -76,7 +76,11 @@ func Load() {
7676 ENV .PORT = os .Getenv ("PORT" )
7777 ENV .API_URL = os .Getenv ("SIGNAL_API_URL" )
7878
79- ENV .API_TOKEN = os .Getenv ("API_TOKEN" )
79+ apiToken := os .Getenv ("API_TOKENS" )
80+
81+ if apiToken == "" {
82+ apiToken = os .Getenv ("API_TOKEN" )
83+ }
8084
8185 blockedEndpointJSON := os .Getenv ("BLOCKED_ENDPOINTS" )
8286 recipientsJSON := os .Getenv ("RECIPIENTS" )
@@ -85,59 +89,21 @@ func Load() {
8589
8690 log .Info ("Loaded Environment Variables" )
8791
88- if ENV .API_TOKEN == "" {
92+ apiTokens , err := utils .StringToArray (apiToken )
93+
94+ if err != nil {
8995 log .Warn ("No API TOKEN provided this is NOT recommended" )
9096
9197 log .Info ("Disabling Security Features due to incomplete Congfiguration" )
9298
9399 ENV .BLOCKED_ENDPOINTS = []string {}
100+ } else {
101+ ENV .API_TOKENS = apiTokens
94102 }
95103
96- if blockedEndpointJSON != "" {
97- var blockedEndpoints [] string
104+ ENV . BLOCKED_ENDPOINTS = utils. GetJson [[] string ]( blockedEndpointJSON )
105+ ENV . MESSAGE_ALIASES = utils. GetJson [[]middlewares. MessageAlias ]( messageAliasesJSON )
98106
99- err := json .Unmarshal ([]byte (blockedEndpointJSON ), & blockedEndpoints )
100-
101- if err != nil {
102- log .Error ("Could not decode Blocked Endpoints: " , blockedEndpointJSON )
103- }
104-
105- ENV .BLOCKED_ENDPOINTS = blockedEndpoints
106- }
107-
108- if messageAliasesJSON != "" {
109- var msgAliases []middlewares.MessageAlias
110-
111- err := json .Unmarshal ([]byte (messageAliasesJSON ), & msgAliases )
112-
113- if err != nil {
114- log .Error ("Could not decode Message Aliases " , variablesJSON )
115- }
116-
117- ENV .MESSAGE_ALIASES = msgAliases
118- }
119-
120- if variablesJSON != "" {
121- var variables map [string ]interface {}
122-
123- err := json .Unmarshal ([]byte (variablesJSON ), & variables )
124-
125- if err != nil {
126- log .Error ("Could not decode Variables " , variablesJSON )
127- }
128-
129- ENV .VARIABLES = variables
130- }
131-
132- if recipientsJSON != "" {
133- var recipients []string
134-
135- err := json .Unmarshal ([]byte (recipientsJSON ), & recipients )
136-
137- if err != nil {
138- log .Error ("Could not decode Variables " , variablesJSON )
139- }
140-
141- ENV .VARIABLES ["RECIPIENTS" ] = recipients
142- }
107+ ENV .VARIABLES = utils.GetJson [map [string ]any ](variablesJSON )
108+ ENV .VARIABLES ["RECIPIENTS" ] = utils.GetJson [[]string ](recipientsJSON )
143109}
0 commit comments