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

Open
rochacbruno opened this Issue Sep 21, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@rochacbruno
Owner

rochacbruno commented Sep 21, 2018

Depends on #84

Traversal of nested dictionaries should also be possible in validators.

having settings.yaml

DEFAULT:
    REDIS:
        HOST: localhost
        PORT: 1234

It is currently possible to write validator to ensure:

REDIS key is set and it is a dict and it has the keys HOST and PORT being HOST a str and PORT as int

from dynaconf import settings, Validator

settings.validators.register(
    Validator(
        'REDIS', 
        must_exist=True, 
        is_type_of=dict.
        condition=lambda v: (
            'HOST' in v and 'PORT' in v
        ) and (
            isinstance(v.HOST, int) and isinstance(v.PORT, int)
        )
    ),
)

RFC: Allow the above validation to be written using dot notation

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

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-toml

@rochacbruno rochacbruno changed the title from Allow dot traversing for validators to RFC: Allow dot traversing for validators Sep 21, 2018

@rochacbruno rochacbruno added the RFC label Sep 21, 2018

@suvratjain1995

This comment has been minimized.

Show comment
Hide comment
@suvratjain1995

suvratjain1995 Oct 1, 2018

@rochacbruno I would like to work on this enhancement.

suvratjain1995 commented Oct 1, 2018

@rochacbruno I would like to work on this enhancement.

@rochacbruno

This comment has been minimized.

Show comment
Hide comment
@rochacbruno

rochacbruno Oct 1, 2018

Owner

@suvratjain1995 cool! this issue depends on the implementation of #84

Owner

rochacbruno commented Oct 1, 2018

@suvratjain1995 cool! this issue depends on the implementation of #84

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment