/
config_request.go
60 lines (54 loc) · 1.48 KB
/
config_request.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
package builder_api
import (
ac "github.com/chef/automate/api/config/shared"
w "github.com/chef/automate/api/config/shared/wrappers"
)
func NewConfigRequest() *ConfigRequest {
return &ConfigRequest{
V1: &ConfigRequest_V1{
Sys: &ConfigRequest_V1_System{
Service: &ConfigRequest_V1_System_Service{},
Log: &ConfigRequest_V1_System_Log{},
},
},
}
}
func DefaultConfigRequest() *ConfigRequest {
c := NewConfigRequest()
c.V1.Sys.Service.Host = w.String("127.0.0.1")
c.V1.Sys.Service.Port = w.Int32(10103)
return c
}
func (c *ConfigRequest) Validate() error {
return nil
}
func (c *ConfigRequest) PrepareSystemConfig(creds *ac.TLSCredentials) (ac.PreparedSystemConfig, error) {
sys := c.V1.Sys
sys.Tls = creds
return c.V1.Sys, nil
}
// SetGlobalConfig imports settings from the global configuration
func (c *ConfigRequest) SetGlobalConfig(g *ac.GlobalConfig) {
var level string
if c.GetV1().GetSys().GetLog().GetLevel().GetValue() != "" {
level = c.GetV1().GetSys().GetLog().GetLevel().GetValue()
} else {
level = g.GetV1().GetLog().GetLevel().GetValue()
}
switch level {
case "debug":
level = "debug"
case "", "info", "warn", "warning", "panic", "fatal":
level = "error"
default:
// We'll allow it (this will cover trace)
}
if level == "" {
c.GetV1().GetSys().GetLog().Level = nil
} else {
c.GetV1().GetSys().GetLog().Level = w.String(level)
}
if len(c.GetV1().GetSys().GetLog().GetScopedLevels()) == 0 {
c.GetV1().GetSys().GetLog().ScopedLevels = nil
}
}