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

Only validate config for enabled signers #217

Open
johanix opened this issue Mar 22, 2023 · 0 comments
Open

Only validate config for enabled signers #217

johanix opened this issue Mar 22, 2023 · 0 comments

Comments

@johanix
Copy link
Contributor

johanix commented Mar 22, 2023

As we gain support for additional signers, that may or may not be enabled, it obviously doesn't work to validate the config for something that isn't configured. So validation must be configurable, preferably on the "signers.{name}.enabled" key. I suggest something like this:

func ValidateBySection(config *Config, cfgfile string) error {
	var configsections = make(map[string]interface{}, 5)
	validate := validator.New()

	log.Printf(`
*** Config validation: Note that sections that do not have an 'enabled=true' key 
*** are not validated, but may still be used.`)

	configsections["signers.desec"] = config.Signers.DeSEC
	configsections["signers.foobar"] = config.Signers.Foobar	

        for k, data := range configsections {
		if viper.GetBool(fmt.Sprintf("%s.enabled", k)) {
			log.Printf("Validating config for %s section", k)
			if err := validate.Struct(data); err != nil {
				log.Fatalf("Config %s, section %s: missing required attributes:\n%v\n", cfgfile, k, err)
			}
		} else {
			log.Printf("Config %s, section %s: not enabled (requires %s.enabled=true), not validating its config.",
				cfgfile, k, k)
		}
	}
        e=return nil
}
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

No branches or pull requests

1 participant