This repository has been archived by the owner on Jul 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
215 lines (201 loc) · 7.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package config
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/xchapter7x/lo"
)
func NewConfig(c *cli.Context) (*Config, error) {
//check for required fields
if err := checkRequired(c); err != nil {
return nil, err
}
config := &Config{
AZs: c.StringSlice("az"),
StemcellName: c.String("stemcell-name"),
NetworkName: c.String("network"),
SystemDomain: c.String("system-domain"),
AppDomains: c.StringSlice("app-domain"),
NATSPort: c.Int("nats-port"),
HostKeyFingerprint: c.String("host-key-fingerprint"),
SupportAddress: c.String("support-address"),
MinCliVersion: c.String("min-cli-version"),
SharePath: c.String("nfs-share-path"),
AllowSSHAccess: c.Bool("allow-app-ssh-access"),
SkipSSLCertVerify: c.BoolT("skip-cert-verify"),
UAALoginProtocol: c.String("uaa-login-protocol"),
SyslogAddress: c.String("syslog-address"),
SyslogPort: c.Int("syslog-port"),
SyslogTransport: c.String("syslog-transport"),
DopplerZone: c.String("doppler-zone"),
DopplerMessageDrainBufferSize: c.Int("doppler-drain-buffer-size"),
BBSRequireSSL: c.BoolT("bbs-require-ssl"),
CCUploaderJobPollInterval: c.Int("cc-uploader-poll-interval"),
CCExternalPort: c.Int("cc-external-port"),
SelfServiceLinksEnabled: c.BoolT("uaa-enable-selfservice-links"),
SignupsEnabled: c.BoolT("uaa-signups-enabled"),
CompanyName: c.String("uaa-company-name"),
ProductLogo: c.String("uaa-product-logo"),
SquareLogo: c.String("uaa-square-logo"),
FooterLegalText: c.String("uaa-footer-legal-txt"),
LDAPUrl: c.String("uaa-ldap-url"),
LDAPUserDN: c.String("uaa-ldap-user-dn"),
LDAPSearchBase: c.String("uaa-ldap-search-base"),
LDAPSearchFilter: c.String("uaa-ldap-search-filter"),
LDAPMailAttributeName: c.String("uaa-ldap-mail-attributename"),
LDAPEnabled: c.BoolT("uaa-ldap-enabled"),
HAProxySkip: c.BoolT("skip-haproxy"),
MySQLProxyExternalHost: c.String("mysql-proxy-external-host"),
RouterEnableSSL: c.Bool("router-enable-ssl"),
NFSAllowFromNetworkCIDR: c.StringSlice("nfs-allow-from-network-cidr"),
LoggregatorPort: c.Int("loggregator-port"),
}
config.IP = NewIP(c)
config.VMType = NewVMType(c)
config.Disk = NewDisk(c)
config.Secret = NewSecret(c)
config.User = NewUser(c)
config.InstanceCount = NewInstanceCount(c)
if config.MySQLProxyExternalHost == "" {
config.MySQLProxyExternalHost = config.MySQLProxyIPs[0]
}
if certs, err := NewCerts(c); err != nil {
return nil, err
} else {
config.Certs = certs
}
return config, nil
}
type Config struct {
AZs []string
StemcellName string
NetworkName string
SystemDomain string
AppDomains []string
AllowSSHAccess bool
SkipSSLCertVerify bool
NATSPort int
UAALoginProtocol string
SyslogAddress string
SyslogPort int
SyslogTransport string
DopplerZone string
DopplerMessageDrainBufferSize int
BBSRequireSSL bool
CCUploaderJobPollInterval int
CCExternalPort int
SelfServiceLinksEnabled bool
SignupsEnabled bool
CompanyName string
ProductLogo string
SquareLogo string
FooterLegalText string
LDAPUrl string
LDAPUserDN string
LDAPSearchBase string
LDAPSearchFilter string
LDAPMailAttributeName string
LDAPEnabled bool
SharePath string
HostKeyFingerprint string
SupportAddress string
MinCliVersion string
HAProxySkip bool
MySQLProxyExternalHost string
RouterEnableSSL bool
NFSAllowFromNetworkCIDR []string
LoggregatorPort int
*Certs
IP
VMType
Disk
Secret
InstanceCount
User
}
func RequiredStringFlags() []string {
return []string{
"stemcell-name",
"network",
"system-domain",
"host-key-fingerprint",
"support-address",
"min-cli-version",
"nfs-share-path",
"uaa-login-protocol",
"doppler-zone",
"uaa-company-name",
"uaa-product-logo",
"uaa-square-logo",
"uaa-footer-legal-txt",
}
}
func RequiredStringSliceFlags() []string {
return []string{
"az",
"app-domain",
"nfs-allow-from-network-cidr",
}
}
func RequiredIntFlags() []string {
return []string{
"nats-port",
"doppler-drain-buffer-size",
"cc-uploader-poll-interval",
"cc-external-port",
"loggregator-port",
}
}
func (c *Config) MySQLProxyHost() string {
return c.MySQLProxyIPs[0]
}
func checkRequired(c *cli.Context) error {
invalidNames := []string{}
invalidNames = append(invalidNames, checkRequiredStringFlags(c, RequiredStringFlags())...)
invalidNames = append(invalidNames, checkRequiredStringSliceFlags(c, RequiredStringSliceFlags())...)
invalidNames = append(invalidNames, checkRequiredIntFlags(c, RequiredIntFlags())...)
invalidNames = append(invalidNames, checkRequiredStringFlags(c, RequiredCertFlags())...)
invalidNames = append(invalidNames, checkRequiredStringFlags(c, RequiredDiskFlags())...)
invalidNames = append(invalidNames, checkRequiredIntFlags(c, RequiredInstanceCountFlags())...)
invalidNames = append(invalidNames, checkRequiredStringFlags(c, RequiredSecretFlags())...)
invalidNames = append(invalidNames, checkRequiredStringFlags(c, RequiredUserFlags())...)
invalidNames = append(invalidNames, checkRequiredStringFlags(c, RequiredVMTypeFlags())...)
invalidNames = append(invalidNames, checkRequiredStringFlags(c, RequiredIPFlags())...)
invalidNames = append(invalidNames, checkRequiredStringSliceFlags(c, RequiredIPSliceFlags())...)
if len(invalidNames) > 0 {
return fmt.Errorf("Sorry you need to provide %v flags to continue", invalidNames)
}
return nil
}
func checkRequiredIntFlags(c *cli.Context, requiredFlags []string) []string {
invalidNames := []string{}
for _, name := range requiredFlags {
if c.Int(name) == 0 {
invalidNames = append(invalidNames, name)
} else {
lo.G.Debug(name, "==>", c.String(name))
}
}
return invalidNames
}
func checkRequiredStringFlags(c *cli.Context, requiredFlags []string) []string {
invalidNames := []string{}
for _, name := range requiredFlags {
if c.String(name) == "" {
invalidNames = append(invalidNames, name)
} else {
lo.G.Debug(name, "==>", c.String(name))
}
}
return invalidNames
}
func checkRequiredStringSliceFlags(c *cli.Context, requiredFlags []string) []string {
invalidNames := []string{}
for _, name := range requiredFlags {
if len(c.StringSlice(name)) == 0 {
invalidNames = append(invalidNames, name)
} else {
lo.G.Debug(name, "==>", c.StringSlice(name))
}
}
return invalidNames
}