/
globals.go
72 lines (56 loc) · 1.69 KB
/
globals.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
package auth0
import (
"os"
logger "github.com/kthomas/go-logger"
)
const defaultauth0APINamespace = "v2"
var (
// auth0APINamespace is the configured Auth0 API namespace (i.e., 'v2')
auth0APINamespace string
// auth0Domain is the configured Auth0 domain
auth0Domain string
// auth0ClientID is the configured Auth0 client id
auth0ClientID string
// auth0ClientSecret is the configured Auth0 client secret
auth0ClientSecret string
// auth0Audience is the configured Auth0 audience
auth0Audience string
// log is the configured logger
log *logger.Logger
)
func init() {
lvl := os.Getenv("AUTH0_LOG_LEVEL")
if lvl == "" {
lvl = "INFO"
}
var endpoint *string
if os.Getenv("SYSLOG_ENDPOINT") != "" {
endpt := os.Getenv("SYSLOG_ENDPOINT")
endpoint = &endpt
}
log = logger.NewLogger("auth0", lvl, endpoint)
}
// RequireAuth0 reads the Auth0 configuration from the environment
func RequireAuth0() {
log.Debugf("Attempting to read required Auth0 configuration from environment")
auth0APINamespace = os.Getenv("AUTH0_API_NAMESPACE")
if auth0APINamespace == "" {
auth0APINamespace = defaultauth0APINamespace
}
auth0Domain = os.Getenv("AUTH0_DOMAIN")
if auth0Domain == "" {
log.Panicf("Failed to parse AUTH0_DOMAIN environment variable")
}
auth0ClientID = os.Getenv("AUTH0_CLIENT_ID")
if auth0ClientID == "" {
log.Panicf("Failed to parse AUTH0_CLIENT_ID environment variable")
}
auth0ClientSecret = os.Getenv("AUTH0_CLIENT_SECRET")
if auth0ClientSecret == "" {
log.Panicf("Failed to parse AUTH0_CLIENT_SECRET environment variable")
}
auth0Audience = os.Getenv("AUTH0_AUDIENCE")
if auth0Audience == "" {
log.Panicf("Failed to parse AUTH0_AUDIENCE environment variable")
}
}