mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 05:40:11 +01:00
Bailout unknown config (#216)
* provider now checks for undecoded config entries and returns an error if any are found * Specific error message now in server logs, more general message for user * Changes spaces to tabs for formatting consistency * Further formatting * Improved handling of undecoded TOML fields in config. * aggregator now checks for not decoded config options Co-authored-by: Jan Höfelmeyer <Jan Höfelmeyer jhoefelmeyer@intevation.de> Co-authored-by: Sascha L. Teichmann <sascha.teichmann@intevation.de>
This commit is contained in:
parent
cbb9c7a7a1
commit
46f79a9e24
3 changed files with 15 additions and 3 deletions
|
|
@ -228,10 +228,15 @@ func loadConfig(path string) (*config, error) {
|
|||
}
|
||||
|
||||
var cfg config
|
||||
if _, err := toml.DecodeFile(path, &cfg); err != nil {
|
||||
md, err := toml.DecodeFile(path, &cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if undecoded := md.Undecoded(); len(undecoded) != 0 {
|
||||
return nil, fmt.Errorf("could not parse %q from config.toml", undecoded)
|
||||
}
|
||||
|
||||
cfg.setDefaults()
|
||||
|
||||
if err := cfg.check(); err != nil {
|
||||
|
|
|
|||
|
|
@ -222,10 +222,16 @@ func loadConfig() (*config, error) {
|
|||
path = defaultConfigPath
|
||||
}
|
||||
var cfg config
|
||||
if _, err := toml.DecodeFile(path, &cfg); err != nil {
|
||||
|
||||
md, err := toml.DecodeFile(path, &cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if undecoded := md.Undecoded(); len(undecoded) != 0 {
|
||||
return nil, fmt.Errorf("could not parse %q from config.toml", undecoded)
|
||||
}
|
||||
|
||||
// Preset defaults
|
||||
|
||||
if cfg.OpenPGPPrivateKey == "" {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,8 @@ func main() {
|
|||
cfg, err := loadConfig()
|
||||
if err != nil {
|
||||
cgi.Serve(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
http.Error(rw, fmt.Sprintf("Config error: %v\n", err), http.StatusInternalServerError)
|
||||
http.Error(rw, "Something went wrong. Check server logs for more details",
|
||||
http.StatusInternalServerError)
|
||||
}))
|
||||
log.Fatalf("error: %v\n", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue