-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
77 lines (65 loc) · 1.77 KB
/
options.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
package options
import (
"fmt"
"strconv"
"github.com/spf13/viper"
)
const (
defaultDBType = "mysql"
defaultDBSrc = "file::memory:?cache=shared"
maxAppScaleCount = 1
maxAppDeployCount = 7
)
func init() {
viper.SetDefault("db.type", defaultDBType)
viper.SetDefault("db.src", defaultDBSrc)
viper.SetDefault("constraints.max-scale", maxAppScaleCount)
viper.SetDefault("constraints.max-app", maxAppDeployCount)
}
// GetDBType returns database type
func GetDBType() string {
return viper.GetString("db.type")
}
// GetDBSrc returns database source string
func GetDBSrc() string {
return viper.GetString("db.src")
}
// GetDefaultDBSrc returns database source string
func GetDefaultDBSrc() string {
return defaultDBSrc
}
// GetDBCreds returns MySQL db string
func GetDBCreds() string {
return fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?parseTime=true",
viper.GetString("db.user"),
viper.GetString("db.password"),
viper.GetString("db.host"),
viper.GetString("db.port"),
viper.GetString("db.name"))
}
// GetConstraintMaxScale returns the maximum app scale count.
func GetConstraintMaxScale() int {
max_scale_str := viper.GetString("constraints.max-scale")
max_scale, err := strconv.Atoi(max_scale_str)
if err != nil {
return maxAppScaleCount
}
return max_scale
}
// GetAuth0ClientId returns the auth0 client-id.
func GetAuth0ClientId() string {
return viper.GetString("auth0.client-id")
}
// GetConstraintMaxAppDeploy returns the maximum apps allowed to deploy.
func GetConstraintMaxAppDeploy() int {
max_app_str := viper.GetString("constraints.max-app")
max_app, err := strconv.Atoi(max_app_str)
if err != nil {
return maxAppDeployCount
}
return max_app
}
// GetJWKSURL returns the JWKS-URL for validation.
func GetJWKSURL() string {
return viper.GetString("jwks.url")
}