mirror of
https://github.com/joohoi/acme-dns.git
synced 2025-07-08 23:07:42 +07:00
Strict decoding of config file
Abort on unrecognized options or if general.domain is missing Fixes #292
This commit is contained in:
9
util.go
9
util.go
@ -32,16 +32,23 @@ func fileIsAccessible(fname string) bool {
|
|||||||
|
|
||||||
func readConfig(fname string) (DNSConfig, error) {
|
func readConfig(fname string) (DNSConfig, error) {
|
||||||
var conf DNSConfig
|
var conf DNSConfig
|
||||||
_, err := toml.DecodeFile(fname, &conf)
|
md, err := toml.DecodeFile(fname, &conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Return with config file parsing errors from toml package
|
// Return with config file parsing errors from toml package
|
||||||
return conf, err
|
return conf, err
|
||||||
}
|
}
|
||||||
|
undecoded := md.Undecoded()
|
||||||
|
if len(undecoded) > 0 {
|
||||||
|
return conf, fmt.Errorf("Unexpected keys: %v", undecoded)
|
||||||
|
}
|
||||||
return prepareConfig(conf)
|
return prepareConfig(conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepareConfig checks that mandatory values exist, and can be used to set default values in the future
|
// prepareConfig checks that mandatory values exist, and can be used to set default values in the future
|
||||||
func prepareConfig(conf DNSConfig) (DNSConfig, error) {
|
func prepareConfig(conf DNSConfig) (DNSConfig, error) {
|
||||||
|
if conf.General.Domain == "" {
|
||||||
|
return conf, errors.New("missing general configuration option \"domain\"")
|
||||||
|
}
|
||||||
if conf.Database.Engine == "" {
|
if conf.Database.Engine == "" {
|
||||||
return conf, errors.New("missing database configuration option \"engine\"")
|
return conf, errors.New("missing database configuration option \"engine\"")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user