forked from cloudfoundry/bosh-cli
/
config.go
51 lines (40 loc) · 1.11 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
package acceptance
import (
"encoding/json"
"errors"
"os"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
type Config struct {
StemcellPath string `json:"stemcell_path"`
CPIReleasePath string `json:"cpi_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) Validate() error {
if c.StemcellPath == "" {
return errors.New("Must provide 'stemcell_path' in config")
}
if c.CPIReleasePath == "" {
return errors.New("Must provide 'cpi_release_path' in config")
}
if c.DummyCompiledReleasePath == "" {
return errors.New("Must provide 'dummy_compiled_release_path' in config")
}
return nil
}