From c802a3397e242d2075ed08b2b83d59725505d28f Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 17 May 2020 17:25:53 -0700 Subject: [PATCH] Fix warnings about configuration values; should always use the snake case since we're using a marshaled value --- config/config.go | 6 +++--- config/config_docker.go | 4 ++-- parser/helpers.go | 5 +---- parser/parser.go | 8 ++++++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/config/config.go b/config/config.go index 5e0eeec..f79b0f0 100644 --- a/config/config.go +++ b/config/config.go @@ -46,9 +46,9 @@ type Configuration struct { // validate against it. AuthenticationToken string `json:"token" yaml:"token"` - Api ApiConfiguration - System SystemConfiguration - Docker DockerConfiguration + Api ApiConfiguration `json:"api" yaml:"api"` + System SystemConfiguration `json:"system" yaml:"system"` + Docker DockerConfiguration `json:"docker" yaml:"docker"` // The amount of time in seconds that should elapse between disk usage checks // run by the daemon. Setting a higher number can result in better IO performance diff --git a/config/config_docker.go b/config/config_docker.go index 5b3f17f..2828356 100644 --- a/config/config_docker.go +++ b/config/config_docker.go @@ -15,7 +15,7 @@ type dockerNetworkInterfaces struct { type DockerNetworkConfiguration struct { // The interface that should be used to create the network. Must not conflict // with any other interfaces in use by Docker or on the system. - Interface string `default:"172.18.0.1"` + Interface string `default:"172.18.0.1" json:"interface" yaml:"interface"` // The DNS settings for containers. Dns []string `default:"[\"1.1.1.1\", \"1.0.0.1\"]"` @@ -45,7 +45,7 @@ type DockerConfiguration struct { UpdateImages bool `default:"true" json:"update_images" yaml:"update_images"` // The location of the Docker socket. - Socket string `default:"/var/run/docker.sock"` + Socket string `default:"/var/run/docker.sock" json:"socket" yaml:"socket"` // Defines the location of the timezone file on the host system that should // be mounted into the created containers so that they all use the same time. diff --git a/parser/helpers.go b/parser/helpers.go index d994aca..afee5ad 100644 --- a/parser/helpers.go +++ b/parser/helpers.go @@ -165,11 +165,8 @@ func (f *ConfigurationFile) LookupConfigurationValue(cfr ConfigurationFileReplac ) var path []string - // The camel casing is important here, the configuration for the Daemon does not use - // JSON, and as such all of the keys will be generated in CamelCase format, rather than - // the expected snake_case from the old Daemon. for _, value := range strings.Split(huntPath, ".") { - path = append(path, strcase.ToCamel(value)) + path = append(path, strcase.ToSnake(value)) } // Look for the key in the configuration file, and if found return that value to the diff --git a/parser/parser.go b/parser/parser.go index 52b9213..75b4aa2 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -124,8 +124,12 @@ func (cfr *ConfigurationFileReplacement) UnmarshalJSON(data []byte) error { func (f *ConfigurationFile) Parse(path string, internal bool) error { zap.S().Debugw("parsing configuration file", zap.String("path", path), zap.String("parser", string(f.Parser))) - mb, _ := json.Marshal(config.Get()) - f.configuration = mb + if mb, err := json.Marshal(config.Get()); err != nil { + return err + } else { + f.configuration = mb + } + var err error