Utility function to fetch docker secrets/envvars.
For config values (flask projects) i like to fetch docker secrets and fall back to environment variables for development. This module provides a function to make this a one-liner: use docker secret -> fall back to envvar -> fall back to default value.
The function also provides the possibility to automatically cast the value or specify a custom directory for secrets.
Following assumptions are being made (params):
autocast_name=True
: secrets are lower-case, envvars upper-case. automatic conversion of name can be switched off via autocast_name=Falsecast_to=str
: fill in desired datatype. special case bool: 'True'/'true' will be True. 'False'/'false' will be Falsegetenv=True
: you want to fall back to envvar. can be switched of via getenv=Falsedefault=None
safe=True
: returns None if name not found or cast fails. If you want exceptions: safe=Falsesecrets_dir=/var/run/secrets
from get_docker_secret import get_docker_secret
value = get_docker_secret('secret_key', default='very_secret')
python setup.py test
not tested under windows
- Fixed: Strip values read from file.
- Initial publish