forked from oracle/smith
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
62 lines (56 loc) · 2 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
package main
import (
"io/ioutil"
"github.com/Sirupsen/logrus"
"github.com/ghodss/yaml"
)
type MockDef struct {
Config string `json:"config,omitempty"`
PreBuild string `json:"pre-build,omitempty"`
PostBuild string `json:"post-build,omitempty"`
Deps []string `json:"deps,omitempty"`
DebugInfo bool `json:"debuginfo,omitempty"`
DebugDeps []string `json:"debugdeps,omitempty"`
DebugPaths []string `json:"debugpaths,omitempty"`
}
type ConfigDef struct {
Type string `json:"type,omitempty"` //defaults to "mock"
Mock MockDef `json:"mock,omitempty"`
Package string `json:"package,omitempty"`
Paths []string `json:"paths,omitempty"`
Excludes []string `json:"excludes,omitempty"`
Parent string `json:"parent,omitempty"`
Nss bool `json:"nss,omitempty"`
Root bool `json:"root,omitempty"`
User string `json:"user,omitempty"`
Groups []string `json:"groups,omitempty"`
Mounts []string `json:"mounts,omitempty"`
Entrypoint []string `json:"entrypoint,omitempty"`
Cmd []string `json:"cmd,omitempty"`
Dir string `json:"dir,omitempty"`
Env []string `json:"env,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Ports map[string]struct{} `json:"ports,omitempty"`
}
func ReadConfig(path string) (*ConfigDef, error) {
ydef, err := ioutil.ReadFile(path)
if err != nil {
logrus.Errorf("Failed to read %v: %v", path, err)
return nil, err
}
var def ConfigDef
err = yaml.Unmarshal(ydef, &def)
if err != nil {
logrus.Errorf("Failed to unmarshall %v: %v", path, err)
return nil, err
}
return &def, nil
}
func (n *ConfigDef) WriteConfig(path string) error {
data, err := yaml.Marshal(n)
if err != nil {
return err
}
logrus.Debugf("Writing normalized config to %v", path)
return ioutil.WriteFile(path, data, 0644)
}