Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict decoding of config file #294

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\"")
}
Expand Down