This repository has been archived by the owner on Jun 18, 2020. It is now read-only.
forked from waffle-iron/core0
-
Notifications
You must be signed in to change notification settings - Fork 2
/
settings.go
103 lines (83 loc) · 1.92 KB
/
settings.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
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
97
98
99
100
101
102
103
package settings
import (
"github.com/op/go-logging"
"github.com/threefoldtech/0-core/base/utils"
)
var (
log = logging.MustGetLogger("settings")
)
const (
//ConfigSuffix config file ext
ConfigSuffix = ".toml"
)
//Logger settings
type Logger struct {
Levels []uint16 `json:"levels"`
}
//Extension cmd config
type Extension struct {
//binary to execute
Binary string `json:"binary"`
//script search path
Cwd string `json:"cwd"`
//(optional) Env variables
Env map[string]string `json:"env"`
Args []string `json:"args"`
key string `json:"key"`
}
func (e *Extension) Key() string {
return e.key
}
//Security certificate path
type Security struct {
CertificateAuthority string
ClientCertificate string
ClientCertificateKey string
}
type Globals map[string]string
func (g Globals) Get(key string, def ...string) string {
v, ok := g[key]
if !ok && len(def) == 1 {
return def[0]
}
return v
}
//Settings main agent settings
type AppSettings struct {
Main struct {
MaxJobs int `json:"max_jobs"`
Include []string `json:"include"`
Network string `json:"network"`
LogLevel string `json:"log_level"` //deprecated (not used)
} `json:"main"`
Globals Globals `json:"globals"`
Extension map[string]Extension `json:"extension"`
Logging struct {
File Logger `json:"file"`
Ledis struct {
Logger `json:"ledis"`
Size int64 `json:"size"`
}
} `json:"logger"`
Containers struct {
MaxCount int `json:"max_count"`
} `json:"containers"`
Stats struct {
Enabled bool `json:"enabled"`
} `json:"stats"`
}
var Settings AppSettings
func (s *AppSettings) Validate() []error {
if s.Main.LogLevel == "" {
s.Main.LogLevel = "info"
}
return nil
}
//GetSettings loads main settings from a filename
func LoadSettings(filename string) error {
//that's the main config file, panic if can't load
if err := utils.LoadTomlFile(filename, &Settings); err != nil {
return err
}
return nil
}