forked from Azure/acs-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
49 lines (43 loc) · 1.07 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
package config
import (
"encoding/json"
"errors"
"io/ioutil"
)
// Deployment represents an ACS cluster deployment on Azure
type Deployment struct {
ClusterDefinition string `json:"cluster_definition"`
Location string `json:"location"`
TestCategory string `json:"category,omitempty"`
SkipValidation bool `json:"skip_validation,omitempty"`
}
// TestConfig represents a cluster config
type TestConfig struct {
Deployments []Deployment `json:"deployments"`
}
func (c *TestConfig) Read(data []byte) error {
return json.Unmarshal(data, c)
}
func (c *TestConfig) validate() error {
for _, d := range c.Deployments {
if d.ClusterDefinition == "" {
return errors.New("Cluster definition is not set")
}
}
return nil
}
// GetTestConfig parses a cluster config
func GetTestConfig(fname string) (*TestConfig, error) {
data, err := ioutil.ReadFile(fname)
if err != nil {
return nil, err
}
config := &TestConfig{}
if err = config.Read(data); err != nil {
return nil, err
}
if err = config.validate(); err != nil {
return nil, err
}
return config, nil
}