forked from rancher/os
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathconfig.go
More file actions
96 lines (78 loc) · 2.24 KB
/
config.go
File metadata and controls
96 lines (78 loc) · 2.24 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package config
import (
"io/ioutil"
"strings"
"github.com/burmilla/os/config/cmdline"
"github.com/burmilla/os/pkg/util"
yaml "github.com/cloudfoundry-incubator/candiedyaml"
)
const Banner = `
____ _ _ _ ____ _____
| _ \\ (_) | | / __ \\ / ____|
| |_) |_ _ _ __ _ __ ___ _| | | __ _| | | | (___
| _ <| | | | '__| '_ ' _ \\| | | |/ _' | | | |\\___ \\
| |_) | |_| | | | | | | | | | | | (_| | |__| |____) |
|____/ \\__,_|_| |_| |_| |_|_|_|_|\\__,_|\\____/|_____/
BurmillaOS \v \n \l
`
func Merge(bytes []byte) error {
data, err := readConfigs(bytes, false, true)
if err != nil {
return err
}
existing, err := readConfigs(nil, false, true, CloudConfigFile)
if err != nil {
return err
}
return WriteToFile(util.Merge(existing, data), CloudConfigFile)
}
func Export(private, full bool) (string, error) {
rawCfg := loadRawConfig("", full)
rawCfg = filterAdditional(rawCfg)
if !private {
rawCfg = filterPrivateKeys(rawCfg)
}
bytes, err := yaml.Marshal(rawCfg)
return string(bytes), err
}
func filterPrivateKeys(data map[interface{}]interface{}) map[interface{}]interface{} {
for _, privateKey := range PrivateKeys {
_, data = filterKey(data, strings.Split(privateKey, "."))
}
return data
}
func filterAdditional(data map[interface{}]interface{}) map[interface{}]interface{} {
for _, additional := range Additional {
_, data = filterKey(data, strings.Split(additional, "."))
}
return data
}
func Get(key string) (interface{}, error) {
cfg := LoadConfig()
data := map[interface{}]interface{}{}
if err := util.ConvertIgnoreOmitEmpty(cfg, &data); err != nil {
return nil, err
}
v, _ := cmdline.GetOrSetVal(key, data, nil)
return v, nil
}
func Set(key string, value interface{}) error {
existing, err := readConfigs(nil, false, true, CloudConfigFile)
if err != nil {
return err
}
_, modified := cmdline.GetOrSetVal(key, existing, value)
c := &CloudConfig{}
if err = util.Convert(modified, c); err != nil {
return err
}
return WriteToFile(modified, CloudConfigFile)
}
func GetKernelVersion() string {
b, err := ioutil.ReadFile("/proc/version")
if err != nil {
return ""
}
elem := strings.Split(string(b), " ")
return elem[2]
}