-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
68 lines (58 loc) · 2.38 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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"github.com/kelseyhightower/envconfig"
)
type brokerConfig struct {
BrokerUsername string `envconfig:"broker_username" required:"true"`
BrokerPassword string `envconfig:"broker_password" required:"true"`
ServiceGUID string `envconfig:"service_guid" required:"true"`
ServiceName string `envconfig:"service_name" required:"true"`
ServiceDescription string `envconfig:"service_desc" default:"A service on K8s"`
ServiceDescriptionFile string `envconfig:"service_desc_file" required:"false"`
ServiceTags []string `envconfig:"service_tags" rquired:"false"`
PlansPath string `envconfig:"service_plans_path" default:"plans.json"`
PlansRevGUIDMap map[string]string
PlanChangeSSupported bool `envconfig:"plan_change_supported" default:"false"`
TemplatesPath string `envconfig:"templates_path" default:"templates"`
KubeconfigPath string `envconfig:"kubeconfig_path" default:""`
LogLevel string `envconfig:"log_level" default:"INFO"`
Port string `envconfig:"port" default:"3000"`
DocsURL string `envconfig:"docsurl" default:"default"`
}
func brokerConfigLoad() (brokerConfig, Plans, error) {
var config brokerConfig
var plans Plans
config.PlansRevGUIDMap = make(map[string]string)
err := envconfig.Process("", &config)
if err != nil {
return brokerConfig{}, nil, err
}
if config.ServiceDescriptionFile != "" {
log.Println("SERVICE_DESC_FILE is set. Loading service description from file and overriding service_desc.")
descBytes, err := ioutil.ReadFile(config.ServiceDescriptionFile)
if err != nil {
return brokerConfig{}, nil, err
}
config.ServiceDescription = string(descBytes)
}
inBuf, err := ioutil.ReadFile(config.PlansPath)
if err != nil {
return brokerConfig{}, nil, err
}
err = json.Unmarshal(inBuf, &plans)
if err != nil {
fmt.Println(err)
return brokerConfig{}, nil, err
}
//if no UUID is given in the plan check if there is an entry in the map or else throw an error.
for planName, plan := range plans {
plan.Name = planName //put the name of the plan in the plan itself, not just as the key.
plans[planName] = plan
config.PlansRevGUIDMap[plan.ID] = planName //populate reverse guid map so we can find plans by ID easily
}
return config, plans, nil
}