forked from LunaNode/lobster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
125 lines (108 loc) · 2.8 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package lobster
import "github.com/scalingdata/gcfg"
import "log"
type ConfigDefault struct {
UrlBase string
AdminEmail string
FromEmail string
ProxyHeader string
Debug bool
Language string
}
type ConfigVm struct {
MaximumIps int
}
type ConfigBilling struct {
BandwidthOverageFee float64
StorageFee float64
Currency string
BillingInterval int
BillingVmMinimum int
DepositMinimum float64
DepositMaximum float64
}
type ConfigBillingNotifications struct {
LowBalanceIntervals int
Frequency int
}
type ConfigBillingTermination struct {
TerminateBalanceIntervals int
TerminateMinNotifications int
SuspendBalanceIntervals int
SuspendMinNotifications int
}
type ConfigSession struct {
Domain string
Secure bool
}
type ConfigDatabase struct {
Host string
Username string
Password string
Name string
}
type ConfigHttp struct {
Addr string
}
type ConfigEmail struct {
Host string
Port int
NoTLS bool
Username string
Password string
}
type ConfigNovnc struct {
Url string
Listen string
}
type ConfigWssh struct {
Url string
Listen string
}
type Config struct {
Default ConfigDefault
Vm ConfigVm
Billing ConfigBilling
BillingNotifications ConfigBillingNotifications
BillingTermination ConfigBillingTermination
Session ConfigSession
Database ConfigDatabase
Http ConfigHttp
Email ConfigEmail
Novnc ConfigNovnc
Wssh ConfigWssh
}
func LoadConfig(cfgPath string) *Config {
var cfg Config
err := gcfg.ReadFileInto(&cfg, cfgPath)
if err != nil {
log.Printf("Error while reading configuration: %s", err.Error())
panic(err)
}
// do some basic checking
if len(cfg.Billing.Currency) != 3 {
log.Printf("Warning: currency is set to [%s], but currency codes should be three characters", cfg.Billing.Currency)
}
if cfg.Billing.BandwidthOverageFee == 0 {
log.Printf("Warning: bandwidth overage fee not set")
}
if cfg.Billing.StorageFee == 0 {
log.Printf("Warning: storage fee not set")
}
if cfg.Billing.BillingInterval == 0 {
log.Printf("Warning: billing interval not set, defaulting to 60 minutes")
cfg.Billing.BillingInterval = 60
}
if cfg.Billing.BillingVmMinimum < 1 {
log.Printf("Warning: minimum VM billing intervals less than 1, setting to 1")
cfg.Billing.BillingVmMinimum = 1
}
if cfg.BillingNotifications.LowBalanceIntervals == cfg.BillingTermination.SuspendBalanceIntervals {
log.Printf("Warning: low balance intervals is set the same as suspend balance intervals")
}
if cfg.BillingNotifications.Frequency == 0 {
log.Printf("Warning: billing notifications frequency not set, defaulting to 24 hours")
cfg.BillingNotifications.Frequency = 24
}
return &cfg
}