forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
86 lines (69 loc) · 1.81 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
package graphql
import (
"fmt"
"os"
"strings"
)
type config struct {
graphQlEndpoint string
localClusterHosts []string
idProviderConfig idProviderConfig
}
type idProviderConfig struct {
dexConfig dexConfig
clientConfig clientConfig
userCredentials userCredentials
}
type dexConfig struct {
baseUrl string
authorizeEndpoint string
tokenEndpoint string
}
type clientConfig struct {
id string
redirectUri string
}
type userCredentials struct {
username string
password string
}
func loadConfig() config {
config := config{
localClusterHosts: make([]string, 0, 2),
}
domain := os.Getenv("DOMAIN")
isLocalClusterStr := strings.ToLower(os.Getenv("IS_LOCAL_CLUSTER"))
graphQlEndpoint := os.Getenv("GRAPHQL_ENDPOINT")
if domain == "" {
domain = "kyma.local"
}
isLocalCluster := isLocalClusterStr == "" || isLocalClusterStr == "true" || isLocalClusterStr == "yes" || isLocalClusterStr == "y"
if graphQlEndpoint == "" {
config.graphQlEndpoint = fmt.Sprintf("https://ui-api.%s/graphql", domain)
if isLocalCluster {
config.addLocalClusterHost(fmt.Sprintf("ui-api.%s", domain))
}
}
config.idProviderConfig = idProviderConfig{
dexConfig: dexConfig{
baseUrl: fmt.Sprintf("https://dex.%s", domain),
authorizeEndpoint: fmt.Sprintf("https://dex.%s/auth", domain),
tokenEndpoint: fmt.Sprintf("https://dex.%s/token", domain),
},
clientConfig: clientConfig{
id: "kyma-client",
redirectUri: "http://127.0.0.1:5555/callback",
},
userCredentials: userCredentials{
username: "admin@kyma.cx",
password: "nimda123",
},
}
if isLocalCluster {
config.addLocalClusterHost(fmt.Sprintf("dex.%s", domain))
}
return config
}
func (c *config) addLocalClusterHost(host string) {
c.localClusterHosts = append(c.localClusterHosts, host)
}