-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp_conf.py
executable file
·37 lines (31 loc) · 1.11 KB
/
app_conf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import dynaconf
from dynaconf import Dynaconf, Validator
from loguru import logger
settings = Dynaconf(
envvar_prefix="DYNACONF",
settings_files=["conf_dir/settings.toml", "conf_dir/.secrets.toml"],
validators=[
# Ensure some parameter meets a condition
# Validator('AGE', lte=30, gte=10),
# validate a value is eq in specific env
# Validator('PROJECT', eq='hello_world', env='production'),
],
)
settings.validators.register(
Validator("app.debug", condition=lambda v: isinstance(v, bool), env="DEBUG"),
)
settings.validators.register(
Validator(
"mode.only_white", condition=lambda v: isinstance(v, bool), env="ONLY_WHITE"
),
)
# raises after all possible errors are evaluated
try:
settings.validators.validate_all()
except dynaconf.ValidationError as e:
accumulative_errors = e.details
logger.error(f"Setting Validation Error {accumulative_errors}")
raise e
# :) Look https://www.dynaconf.com/validation/ for more validations
# `envvar_prefix` = export envvars with `export DYNACONF_FOO=bar`.
# `settings_files` = Load these files in the order.