-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
94 lines (86 loc) · 2.24 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"log"
"os"
"strconv"
"strings"
)
func GetPathFromEnv() string {
path := os.Getenv("SERVER_PATH")
if path == "" {
path = "/"
}
log.Println("SERVER_PATH:", path)
return path
}
func GetPortFromEnv() string {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Println("PORT:", port)
return port
}
func GetJwksURLFromEnv() string {
jwksUrl := os.Getenv("JWKS_URL")
if jwksUrl == "" {
jwksUrl = "https://login.windows.net/common/discovery/keys"
}
log.Println("JWKS_URL:", jwksUrl)
return jwksUrl
}
func GetAuthHeaderNameFromEnv() string {
authHeaderName := os.Getenv("AUTH_HEADER_NAME")
if authHeaderName == "" {
authHeaderName = "Authorization"
}
log.Println("AUTH_HEADER_NAME:", authHeaderName)
return authHeaderName
}
func GetSendBackAccessTokenEnv() bool {
sendAccessTokenBackEnv := os.Getenv("AUTH_HEADER_RETURN")
sendAccessTokenBack := true
if strings.ToLower(sendAccessTokenBackEnv) == "false" {
sendAccessTokenBack = false
}
log.Println("AUTH_HEADER_RETURN:", sendAccessTokenBack)
return sendAccessTokenBack
}
func GetSendBackAccessTokenNameEnv() string {
authHeaderName := os.Getenv("SEND_ACCESS_TOKEN_HEADER_NAME")
if authHeaderName == "" {
authHeaderName = "Authorization"
}
log.Println("SEND_ACCESS_TOKEN_HEADER_NAME:", authHeaderName)
return authHeaderName
}
func GetSendAllClaimsAsJson() bool {
sendAllClaimsAsJsonEnv := os.Getenv("SEND_BACK_CLAIMS")
sendAllClaimsAsJson := true
if strings.ToLower(sendAllClaimsAsJsonEnv) == "false" {
sendAllClaimsAsJson = false
}
log.Println("SEND_BACK_CLAIMS:", sendAllClaimsAsJson)
return sendAllClaimsAsJson
}
func GetClaimContains() []string {
if os.Getenv("CLAIMS_CONTAINS") == "" {
log.Println("CLAIMS CONTAINS check turned off")
return []string{}
}
claimContainsArr := strings.Split(os.Getenv("CLAIMS_CONTAINS"), ",")
log.Println("CLAIMS_CONTAINS:", claimContainsArr)
for i, v := range claimContainsArr {
log.Printf("\tclaim %d: value: %s\n", i, v)
}
return claimContainsArr
}
func GetTTLFromEnv() int {
cacheTTLEnv := os.Getenv("CACHE_TTL")
ttlInSeconds, err := strconv.Atoi(cacheTTLEnv)
if err != nil {
ttlInSeconds = 300 // Default value if conversion fails
}
log.Println("CACHE_TTL:", ttlInSeconds)
return ttlInSeconds
}