-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.go
58 lines (50 loc) · 2.09 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
package config
import (
"encoding/json"
"github.com/pkg/errors"
)
var (
// Version of 3dt code.
Version = "0.4.0"
// APIVer is an API version.
APIVer = 1
)
// Config structure is a main config object
type Config struct {
SystemdUnits []string `json:"-"`
// 3dt flags
FlagCACertFile string `json:"ca-cert"`
FlagPull bool `json:"pull"`
FlagVerbose bool `json:"verbose"`
FlagPort int `json:"port"`
FlagDisableUnixSocket bool `json:"no-unix-socket"`
FlagMasterPort int `json:"master-port"`
FlagAgentPort int `json:"agent-port"`
FlagPullInterval int `json:"pull-interval"`
FlagPullTimeoutSec int `json:"pull-timeout"`
FlagUpdateHealthReportInterval int `json:"health-update-interval"`
FlagExhibitorClusterStatusURL string `json:"exhibitor-ip"`
FlagForceTLS bool `json:"force-tls"`
FlagDebug bool `json:"debug"`
FlagRole string `json:"role"`
FlagIAMConfig string `json:"iam-config"`
// diagnostics job flags
FlagDiagnosticsBundleDir string `json:"diagnostics-bundle-dir"`
FlagDiagnosticsBundleEndpointsConfigFile string `json:"endpoint-config"`
FlagDiagnosticsBundleUnitsLogsSinceString string `json:"diagnostics-units-since"`
FlagDiagnosticsJobTimeoutMinutes int `json:"diagnostics-job-timeout"`
FlagDiagnosticsJobGetSingleURLTimeoutMinutes int `json:"diagnostics-url-timeout"`
FlagCommandExecTimeoutSec int `json:"command-exec-timeout"`
}
// LoadFromViper takes a map of flags with values and updates the config structure.
func (c *Config) LoadFromViper(settings map[string]interface{}) error {
// TODO(mnaboka): use a map to struct library
body, err := json.Marshal(settings)
if err != nil {
return errors.Wrap(err, "unable to marshal config file")
}
if err := json.Unmarshal(body, c); err != nil {
return errors.Wrap(err, "unable to unmarshal config file")
}
return nil
}