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