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

Bad things happen if [general] is missing #292

Open
candlerb opened this issue Feb 21, 2022 · 3 comments · May be fixed by #294
Open

Bad things happen if [general] is missing #292

candlerb opened this issue Feb 21, 2022 · 3 comments · May be fixed by #294

Comments

@candlerb
Copy link

I found this out the hard way... I couldn't understand why acme-dns was trying to do weird stuff, like use the root domain, and then crashing:

# /usr/local/bin/acme-dns
INFO[0000] Using config file                             file=/etc/acme-dns/config.cfg
INFO[0000] Connected to database
DEBU[0000] Adding new record to domain                   domain=. recordtype=SOA
INFO[0000] Listening DNS                                 addr= proto=
FATA[0000] name does not qualify for automatic certificate management:

It turns out that due to a copy-paste error I'd missed [general] from the top of the config file. D'oh!

It would be very helpful if the config parser rejected unexpected or bad settings.

@gbonnefille
Copy link

It is generally hard to do what you request. Config files are read to find values that override default ones. To detect extra-numerous keys requires to have a schema of the configuration and validate any input against this schema. But a INI is « open » by nature.

@candlerb
Copy link
Author

candlerb commented Feb 22, 2022

Seems to be a limit of toml.DecodeFile then.

OK: how about make general.domain a mandatory setting and give a clearer error if it's missing? (e.g. "Required setting 'domain' in section '[general]' is missing")

@candlerb
Copy link
Author

Aha, it is possible: see "Example (StrictDecoding)" at https://godocs.io/github.com/BurntSushi/toml

Something like this should do the trick:

        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)
        }

candlerb added a commit to candlerb/acme-dns that referenced this issue Feb 22, 2022
Abort on unrecognized options or if general.domain is missing

Fixes joohoi#292
@candlerb candlerb linked a pull request Feb 22, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants