-
Notifications
You must be signed in to change notification settings - Fork 180
/
config.go
274 lines (233 loc) · 7.44 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
package acceptance
import (
"errors"
"fmt"
"io/ioutil"
"os"
. "github.com/onsi/ginkgo"
)
type Config struct {
IAAS string
StemcellURL string
AWSAccessKeyID string
AWSSecretAccessKey string
AWSRegion string
AzureClientID string
AzureClientSecret string
AzureRegion string
AzureSubscriptionID string
AzureTenantID string
GCPServiceAccountKey string
GCPRegion string
VSphereNetwork string
VSphereSubnetCIDR string
VSphereVCenterIP string
VSphereVCenterUser string
VSphereVCenterPassword string
VSphereVCenterDC string
VSphereVCenterCluster string
VSphereVCenterRP string
VSphereVCenterDS string
VSphereVCenterDisks string
VSphereVCenterVMs string
VSphereVCenterTemplates string
OpenStackAuthURL string
OpenStackAZ string
OpenStackNetworkID string
OpenStackNetworkName string
OpenStackPassword string
OpenStackUsername string
OpenStackProject string
OpenStackDomain string
OpenStackRegion string
// if bucket is set, statefiledir should be ignored
StateFileDir string
BBLStateBucket string
}
// Loads all of the credentials from environment variables
// to be used in the acceptance test. Validates the presence
// of required credentials before starting up tests.
func LoadConfig() (Config, error) {
config := loadConfigFromEnvVars()
err := validateIAAS(config)
if err != nil {
return Config{}, fmt.Errorf("Error found: %s\n", err)
}
switch config.IAAS {
case "aws":
err = validateAWSCreds(config)
case "azure":
err = validateAzureCreds(config)
case "gcp":
err = validateGCPCreds(config)
case "vsphere":
err = validateVSphereCreds(config)
case "openstack":
err = validateOpenStackCreds(config)
}
if err != nil {
return Config{}, fmt.Errorf("Error Found: %s\nProvide a full set of credentials for a single IAAS.", err)
}
if config.StateFileDir == "" {
dir, err := ioutil.TempDir("", "")
if err != nil {
return Config{}, err
}
config.StateFileDir = dir
}
fmt.Printf("Using state-dir: %s\n", config.StateFileDir)
return config, nil
}
func validateIAAS(config Config) error {
if config.IAAS == "" {
return errors.New("iaas is missing")
}
return nil
}
func validateAWSCreds(config Config) error {
if config.AWSAccessKeyID == "" {
return errors.New("aws access key id is missing")
}
if config.AWSSecretAccessKey == "" {
return errors.New("aws secret access key is missing")
}
if config.AWSRegion == "" {
return errors.New("aws region is missing")
}
return nil
}
func validateAzureCreds(config Config) error {
if config.AzureClientID == "" {
return errors.New("azure client id is missing")
}
if config.AzureClientSecret == "" {
return errors.New("azure client secret is missing")
}
if config.AzureRegion == "" {
return errors.New("azure region is missing")
}
if config.AzureSubscriptionID == "" {
return errors.New("azure subscription id is missing")
}
if config.AzureTenantID == "" {
return errors.New("azure tenant id is missing")
}
return nil
}
func validateGCPCreds(config Config) error {
if config.GCPServiceAccountKey == "" {
return errors.New("gcp service account key is missing")
}
if config.GCPRegion == "" {
return errors.New("gcp region is missing")
}
return nil
}
func validateVSphereCreds(config Config) error {
if config.VSphereVCenterUser == "" {
return errors.New("vsphere vcenter user is missing")
}
if config.VSphereVCenterPassword == "" {
return errors.New("vsphere vcenter password is missing")
}
if config.VSphereVCenterDC == "" {
return errors.New("vsphere vcenter datacenter is missing")
}
if config.VSphereVCenterDS == "" {
return errors.New("vsphere vcenter datastore is missing")
}
if config.VSphereVCenterCluster == "" {
return errors.New("vsphere vcenter cluster is missing")
}
if config.VSphereVCenterRP == "" {
return errors.New("vsphere vcenter resource pool is missing")
}
if config.VSphereVCenterVMs == "" {
return errors.New("vsphere vcenter vms is missing")
}
if config.VSphereVCenterDisks == "" {
return errors.New("vsphere vcenter disks is missing")
}
if config.VSphereVCenterTemplates == "" {
return errors.New("vsphere vcenter templates is missing")
}
if config.VSphereNetwork == "" {
return errors.New("vsphere network name is missing")
}
return nil
}
func validateOpenStackCreds(config Config) error {
if config.OpenStackUsername == "" {
return errors.New("OpenStack user name is missing")
}
if config.OpenStackPassword == "" {
return errors.New("OpenStack password is missing")
}
if config.OpenStackAuthURL == "" {
return errors.New("OpenStack auth URL is missing")
}
if config.OpenStackAZ == "" {
return errors.New("OpenStack AZ is missing")
}
if config.OpenStackNetworkID == "" {
return errors.New("OpenStack network ID is missing")
}
if config.OpenStackNetworkName == "" {
return errors.New("OpenStack network name is missing")
}
if config.OpenStackProject == "" {
return errors.New("OpenStack project is missing")
}
if config.OpenStackDomain == "" {
return errors.New("OpenStack domain is missing")
}
if config.OpenStackRegion == "" {
return errors.New("OpenStack region is missing")
}
return nil
}
func loadConfigFromEnvVars() Config {
return Config{
IAAS: os.Getenv("BBL_IAAS"),
StemcellURL: os.Getenv("STEMCELL_URL"),
AWSAccessKeyID: os.Getenv("BBL_AWS_ACCESS_KEY_ID"),
AWSSecretAccessKey: os.Getenv("BBL_AWS_SECRET_ACCESS_KEY"),
AWSRegion: os.Getenv("BBL_AWS_REGION"),
AzureClientID: os.Getenv("BBL_AZURE_CLIENT_ID"),
AzureClientSecret: os.Getenv("BBL_AZURE_CLIENT_SECRET"),
AzureRegion: os.Getenv("BBL_AZURE_REGION"),
AzureSubscriptionID: os.Getenv("BBL_AZURE_SUBSCRIPTION_ID"),
AzureTenantID: os.Getenv("BBL_AZURE_TENANT_ID"),
GCPServiceAccountKey: os.Getenv("BBL_GCP_SERVICE_ACCOUNT_KEY"),
GCPRegion: os.Getenv("BBL_GCP_REGION"),
VSphereNetwork: os.Getenv("BBL_VSPHERE_NETWORK"),
VSphereSubnetCIDR: os.Getenv("BBL_VSPHERE_SUBNET_CIDR"),
VSphereVCenterIP: os.Getenv("BBL_VSPHERE_VCENTER_IP"),
VSphereVCenterUser: os.Getenv("BBL_VSPHERE_VCENTER_USER"),
VSphereVCenterPassword: os.Getenv("BBL_VSPHERE_VCENTER_PASSWORD"),
VSphereVCenterDC: os.Getenv("BBL_VSPHERE_VCENTER_DC"),
VSphereVCenterCluster: os.Getenv("BBL_VSPHERE_VCENTER_CLUSTER"),
VSphereVCenterRP: os.Getenv("BBL_VSPHERE_VCENTER_RP"),
VSphereVCenterDS: os.Getenv("BBL_VSPHERE_VCENTER_DS"),
VSphereVCenterDisks: os.Getenv("BBL_VSPHERE_VCENTER_DISKS"),
VSphereVCenterVMs: os.Getenv("BBL_VSPHERE_VCENTER_VMS"),
VSphereVCenterTemplates: os.Getenv("BBL_VSPHERE_VCENTER_TEMPLATES"),
OpenStackAuthURL: os.Getenv("BBL_OPENSTACK_AUTH_URL"),
OpenStackAZ: os.Getenv("BBL_OPENSTACK_AZ"),
OpenStackNetworkName: os.Getenv("BBL_OPENSTACK_NETWORK_NAME"),
OpenStackNetworkID: os.Getenv("BBL_OPENSTACK_NETWORK_ID"),
OpenStackPassword: os.Getenv("BBL_OPENSTACK_PASSWORD"),
OpenStackUsername: os.Getenv("BBL_OPENSTACK_USERNAME"),
OpenStackProject: os.Getenv("BBL_OPENSTACK_PROJECT"),
OpenStackDomain: os.Getenv("BBL_OPENSTACK_DOMAIN"),
OpenStackRegion: os.Getenv("BBL_OPENSTACK_REGION"),
StateFileDir: os.Getenv("BBL_STATE_DIR"),
BBLStateBucket: os.Getenv("BBL_STATE_BUCKET"),
}
}
func SkipUnless(match string) {
test := os.Getenv("RUN_TEST")
if test != "" && test != match {
Skip(fmt.Sprintf("RUN_TEST: %s", test))
}
}