-
-
Notifications
You must be signed in to change notification settings - Fork 289
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
RFC: Allow dot traversing for validators #85
Labels
Comments
@rochacbruno I would like to work on this enhancement. |
@suvratjain1995 cool! this issue depends on the implementation of #84 |
jperras
added a commit
to jperras/dynaconf
that referenced
this issue
Oct 22, 2018
One is now able to write: ```python settings.validators.register( Validator('REDIS', must_exist=True, is_type_of=dict), Validator('REDIS.HOST', must_exist=True, is_type_of=str), Validator('REDIS.PORT', must_exist=True, is_type_of=int), ) ``` Which will validate the dotted attributes as nested structures. For example, in yaml: ```yaml DEFAULT: REDIS: HOST: localhost PORT: 1234 ``` This necessitated a slight but non-negligible change in the implementation of `Settings.exists()`, which previously did a shallow check of loaded data. It has now been updated to perform a `Settings.get()` of the key in question, and compares that to a newly defined sentinel value to ensure `None` values do not cause a false negative result. New tests and assertions have been added to cover the new functionality. Docs have been updated to show an example of the nested validator name definition in action. Closes dynaconf#85.
jperras
added a commit
to jperras/dynaconf
that referenced
this issue
Oct 22, 2018
One is now able to write: ```python settings.validators.register( Validator('REDIS', must_exist=True, is_type_of=dict), Validator('REDIS.HOST', must_exist=True, is_type_of=str), Validator('REDIS.PORT', must_exist=True, is_type_of=int), ) ``` Which will validate the dotted attributes as nested structures. For example, in yaml: ```yaml DEFAULT: REDIS: HOST: localhost PORT: 1234 ``` This necessitated a slight but non-negligible change in the implementation of `Settings.exists()`, which previously did a shallow check of loaded data. It has now been updated to perform a `Settings.get()` of the key in question, and compares that to a newly defined sentinel value to ensure `None` values do not cause a false negative result. New tests and assertions have been added to cover the new functionality. Docs have been updated to show an example of the nested validator name definition in action. Closes dynaconf#85.
Sorry for the issue noise – I didn't realize that my forced push rebasing onto my own fork feature branch would cause multiple activity references here. I'll avoid linking the issue no. in commit messages from now on. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Depends on #84
Traversal of nested dictionaries should also be possible in validators.
having
settings.yaml
It is currently possible to write validator to ensure:
REDIS
key is set and it is adict
and it has the keysHOST
andPORT
beingHOST
astr
andPORT
asint
RFC: Allow the above validation to be written using dot notation
Also the above validation can be translated to
toml
validator file as in https://dynaconf.readthedocs.io/en/latest/guides/validation.html#cli-and-dynaconf-validators-tomlThe text was updated successfully, but these errors were encountered: