-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
53 lines (46 loc) · 1.48 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
package goflexer
import (
"io/ioutil"
"log"
"github.com/go-yaml/yaml"
)
// Config holds the configuration options for the flexer context
type Config struct {
URL string `envconfig:"cmp_url" yaml:"cmp_url"`
Username string `envconfig:"cmp_username" yaml:"cpi_api_user"`
Password string `envconfig:"cmp_password" yaml:"cmp_api_key"`
Platform string `envconfig:"cmp_platform"`
Region string `envconfig:"cmp_region"`
AccessToken string `envconfig:"cmp_access_token"`
CodeDir string `envconfig:"nflex_codedir"`
Version string `envconfig:"flexer_version"`
ModuleID string `envconfig:"nflex_module_id"`
DBKeyPrefix string `envconfig:"-" default:"_nflexdb_"`
VerifySSL bool `envconfig:"verify_ssl" default:"true"`
}
type flexerYAMLConfig struct {
Regions map[string]map[string]string `yaml:"regions"`
VerifySSL bool `yaml:"verify_ssl"`
}
// NewConfigFromYAML loads config from a .flexer yaml file
func NewConfigFromYAML() *Config {
conf := &Config{}
fConf := &flexerYAMLConfig{}
yamlFile, err := ioutil.ReadFile("/home/mike/.flexer.yaml")
if err != nil {
log.Printf("yamlFile.Get err #%v ", err)
}
err = yaml.Unmarshal(yamlFile, &fConf)
if err != nil {
log.Fatalf("Unmarshal: %v", err)
}
// TODO Review format as it's really ugly
df, ok := fConf.Regions["default"]
if ok {
conf.URL = df["cmp_url"]
conf.Username = df["cmp_api_key"]
conf.Password = df["cmp_api_secret"]
}
conf.VerifySSL = fConf.VerifySSL
return conf
}