OpenAstronomy/baldrick

Formally register and validate configuration items

Opened this issue · 2 comments

I think each blueprint and plugin should have a way of formally registering configuration items with the app, for instance doing something like:

from flask import current_app
current_app.some_setting = ConfigItem(...)

when the module is loaded. This would allow:

  • Auto-documentation of configuration items for each blueprint/plugin
  • Validation to make sure that we don't access non-existing configuration items
  • Optional validation of the content of the config items (e.g. should be a number, or length of string, etc.)

@Cadair - what do you think?

Sounds like a good plan!

I think we could probably make this a little simpler by restricting the format of the config a little. I.e. each plugin gets it's own key in the top level config dict, with a dict underneath. I also think we should tie this to the app in the minimalist way possible. I.e.

app.config_manager = ConfigManager()

then things register their configs with the manager, and we just use the app as a way to get the reference to the manager.

I wonder if there is a toml schema thing somewhere? If not we could use https://github.com/alecthomas/voluptuous as a way of doing general dict schemas.

We now have a Config object so it should be possible to add validation.