Utility function to fetch docker secrets/envvars.
Project description
get-docker-secret
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
Usage
from get_docker_secret import get_docker_secret
value = get_docker_secret('secret_key', default='very_secret')
Testing
python setup.py test
not tested under windows
Changelog
1.0.2 - 2021-03-19
- Fixed: Only strip trailing newlines from secrets file
1.0.1 - 2019-12-07
- Fixed: Strip values read from file.
1.0.0 - 2018-01-30
- Initial publish
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Close
Hashes for get_docker_secret-1.0.2-py3.9.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc6809c56a6c6f8171f60735c6d6b2f701b2f7d38a9a0b2eb153602f6131189a |
|
MD5 | 1b1e191640ab58f118777f58f50f628f |
|
BLAKE2b-256 | f4d883a81ab65dc994f542e91676c2a87055e4c87209d9d1f73f7666c322c8af |
Close
Hashes for get_docker_secret-1.0.2-py3.8.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1b8e6e70ca84082b5b3feb3a76114d452f06351083c725f3002dd8da7f546c1 |
|
MD5 | e345cbcb37ccda44e39691147f6c819b |
|
BLAKE2b-256 | dcb519cfa48dfa5699432f9d8f1b2d809166799597b513d194bdf000addeffc2 |