-
Notifications
You must be signed in to change notification settings - Fork 10
/
config.go
134 lines (106 loc) · 3.16 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
package main
import (
"fmt"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
type Config struct {
Broker BrokerConfig `yaml:"broker"`
Vault VaultConfig `yaml:"vault"`
Shield ShieldConfig `yaml:"shield"`
BOSH BOSHConfig `yaml:"bosh"`
Debug bool `yaml:"debug"`
WebRoot string `yaml:"web-root"`
Env string `yaml:"env"`
Shareable bool `yaml:"shareable"`
}
type BrokerConfig struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
Port string `yaml:"port"`
BindIP string `yaml:"bind_ip"`
}
type VaultConfig struct {
Address string `yaml:"address"`
Token string `yaml:"token"`
Insecure bool `yaml:"skip_ssl_validation"`
CredPath string `yaml:"credentials"`
}
type ShieldConfig struct {
Enabled bool `yaml:"enabled"`
Address string `yaml:"address"`
Insecure bool `yaml:"skip_ssl_validation"`
Agent string `yaml:"agent"`
AuthMethod string `yaml:"auth_method"` // "token", "local"
Token string `yaml:"token"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Tenant string `yaml:"tenant"` // Full UUID or exact name
Store string `yaml:"store"` // Full UUID or exact name
Schedule string `yaml:"schedule"` // daily, weekly, daily at 11:00
Retain string `yaml:"retain"` // 7d, 7w, ...
EnabledOnTargets []string `yaml:"enabled_on_targets"` // rabbitmq, redis, ...
}
type Uploadable struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
URL string `yaml:"url"`
SHA1 string `yaml:"sha1"`
}
type BOSHConfig struct {
Address string `yaml:"address"`
Username string `yaml:"username"`
Password string `yaml:"password"`
SkipSslValidation bool `yaml:"skip_ssl_validation"`
Stemcells []Uploadable `yaml:"stemcells"`
Releases []Uploadable `yaml:"releases"`
CCPath string `yaml:"cloud-config"` // TODO: CCPath vs CloudConfig & yaml???
CloudConfig string
Network string `yaml:"network"`
}
func ReadConfig(path string) (c Config, err error) {
b, err := ioutil.ReadFile(path)
if err != nil {
return
}
err = yaml.Unmarshal(b, &c)
if err != nil {
return
}
if c.Broker.Username == "" {
c.Broker.Username = "blacksmith"
}
if c.Broker.Password == "" {
c.Broker.Password = "blacksmith"
}
if c.Broker.Port == "" {
c.Broker.Port = "3000"
}
if c.Vault.Address == "" {
return c, fmt.Errorf("Vault Address is not set")
}
if c.BOSH.Address == "" {
return c, fmt.Errorf("BOSH Address is not set")
}
if c.BOSH.Username == "" {
return c, fmt.Errorf("BOSH Username is not set")
}
if c.BOSH.Password == "" {
return c, fmt.Errorf("BOSH Password is not set")
}
if c.BOSH.CCPath != "" {
/* cloud-config provided; try to read it. */
b, err := ioutil.ReadFile(c.BOSH.CCPath)
if err != nil {
return c, fmt.Errorf("BOSH cloud-config file '%s': %s", c.BOSH.CCPath, err)
}
c.BOSH.CloudConfig = string(b)
}
if c.BOSH.Network == "" {
c.BOSH.Network = "blacksmith" // Default
}
os.Setenv("BOSH_NETWORK", c.BOSH.Network) // Required by manifest.go
os.Setenv("VAULT_ADDR", c.Vault.Address)
return
}