forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
85 lines (68 loc) · 2.26 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
package acceptance
import (
"encoding/json"
"errors"
"os"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
type Config struct {
VMUsername string `json:"vm_username"`
VMIP string `json:"vm_ip"`
VMPort string `json:"vm_port"`
PrivateKeyPath string `json:"private_key_path"`
StemcellURL string `json:"stemcell_url"`
StemcellSHA1 string `json:"stemcell_sha1"`
StemcellPath string `json:"stemcell_path"`
CPIReleaseURL string `json:"cpi_release_url"`
CPIReleaseSHA1 string `json:"cpi_release_sha1"`
CPIReleasePath string `json:"cpi_release_path"`
DummyReleasePath string `json:"dummy_release_path"`
DummyTooReleasePath string `json:"dummy_too_release_path"`
DummyCompiledReleasePath string `json:"dummy_compiled_release_path"`
}
func NewConfig(fs boshsys.FileSystem) (*Config, error) {
path := os.Getenv("BOSH_INIT_CONFIG_PATH")
if path == "" {
return &Config{}, errors.New("Must provide config file via BOSH_INIT_CONFIG_PATH environment variable")
}
configContents, err := fs.ReadFile(path)
if err != nil {
return &Config{}, err
}
var config Config
err = json.Unmarshal(configContents, &config)
if err != nil {
return &Config{}, err
}
return &config, nil
}
func (c *Config) IsLocalCPIRelease() bool {
return c.CPIReleasePath != ""
}
func (c *Config) IsLocalStemcell() bool {
return c.StemcellPath != ""
}
func (c *Config) Validate() error {
if c.VMUsername == "" {
return errors.New("Must provide 'vm_username' in config")
}
if c.VMIP == "" {
return errors.New("Must provide 'vm_ip' in config")
}
if c.PrivateKeyPath == "" {
return errors.New("Must provide 'private_key_path' in config")
}
if c.StemcellURL == "" && c.StemcellPath == "" {
return errors.New("Must provide 'stemcell_url' or 'stemcell_path' in config")
}
if c.CPIReleaseURL == "" && c.CPIReleasePath == "" {
return errors.New("Must provide 'cpi_release_url' or 'cpi_release_path' in config")
}
if c.DummyTooReleasePath == "" {
return errors.New("Must provide 'dummy_too_release_path' in config")
}
if c.DummyCompiledReleasePath == "" {
return errors.New("Must provide 'dummy_compiled_release_path' in config")
}
return nil
}