/
config_request.go
61 lines (52 loc) · 1.82 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
61
package user_settings
import (
"strings"
shared "github.com/chef/automate/api/config/shared"
w "github.com/chef/automate/api/config/shared/wrappers"
)
// NewConfigRequest returns a new instance of ConfigRequest with zero values.
func NewConfigRequest() *ConfigRequest {
return &ConfigRequest{
V1: &ConfigRequest_V1{
Sys: &ConfigRequest_V1_System{
Mlsa: &shared.Mlsa{},
Tls: &shared.TLSCredentials{},
Service: &ConfigRequest_V1_System_Service{},
Log: &shared.Log{},
},
Svc: &ConfigRequest_V1_Service{},
},
}
}
// DefaultConfigRequest returns a new instance of ConfigRequest with default values.
func DefaultConfigRequest() *ConfigRequest {
c := NewConfigRequest()
c.V1.Sys.Service.Port = w.Int32(10107)
c.V1.Sys.Log.Level = w.String("info")
c.V1.Sys.Log.Format = w.String("text")
return c
}
// Validate validates that the config is sufficient to start the Service. If
// validation succeeds it will return nil, if it fails it will return a new
// instance of config.InvalidConfigError that has the missing keys and invalid
// fields populated.
func (c *ConfigRequest) Validate() error {
msg := c.GetV1().GetSys().GetService().GetMessage().GetValue()
if strings.Contains(msg, "$") {
cfgErr := shared.NewInvalidConfigError()
cfgErr.AddInvalidValue("user_settings.v1.sys.service.message", "cant have $")
return cfgErr
}
return nil
}
// PrepareSystemConfig returns a system configuration that can be used
// to start the service.
func (c *ConfigRequest) PrepareSystemConfig(certificate *shared.TLSCredentials) (shared.PreparedSystemConfig, error) {
c.V1.Sys.Tls = certificate
return c.V1.Sys, nil
}
// SetGlobalConfig imports settings from the global configuration
func (c *ConfigRequest) SetGlobalConfig(g *shared.GlobalConfig) {
c.V1.Sys.Mlsa = g.GetV1().Mlsa
c.V1.Sys.Log = g.GetV1().GetLog()
}