easy 12factor for django settings
Project description
django-environ
django-environ is the Python package that allows you to use Twelve-factor methodology to configure your Django application with environment variables.
This is the PPB extension of it adding _VAULT
and _FILE
support to environment variable name parsing to read the setting from (respectivelly) that vault key or that file.
This should probably be a fork of the package instead of keeping it as a separate package.. TODO.
Usage
Refer to testapp for a working example.
As in testapp settings, initialize environ:
import ppbenviron
ENV_VAR = ppbenviron.CustomEnv()
ENV_VAR.read_env(BASE_DIR / 'local.env')
ENV_VAR.setup_vault(
'ENVTEST_VAULT_URL',
'ENVTEST_VAULT_TOKEN',
'ENVTEST_VAULT_MOUNT',
'ENVTEST_VAULT_PATHS',
default_url='http://vault.local',
default_token='tok3n',
default_mount='/secrets',
default_paths='staging,production',
)
Define settings:
TEST_SETTING_STR = ENV_VAR('ENVTEST_STR', default='missed')
TEST_SETTING_LIST = ENV_VAR('ENVTEST_LIST', default=['missed'])
Create a testapp/local.env
or define the environment variabls in the current shell:
ENVTEST_VAULT_TOKEN_FILE=/home/myuser/.vault-token
ENVTEST_VAULT_MOUNT=other_mount
ENVTEST_VAULT_PATHS=dev,prd
ENVTEST_STR_FILE=/path/to/file
will load /path/to/file
in TEST_SETTING_STR
.
ENVTEST_STR_VAULT=somepath
will load /other_mount/prd[somepath]
in TEST_SETTING_STR
if it exists otherwise fallback to /other_mount/qa[somepath]
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 Distribution
Hashes for django_environ_ppb-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7faf1016e8dc7cd810c71ecbef5aca0a0def3d40bed3a6aea8e531b100f37893 |
|
MD5 | 94770988b47256e5959a036c1c6991d7 |
|
BLAKE2b-256 | 4685d2597956b1f3c0c45808cf730ff245b51f6c5d5aae0f40047dfdd959e985 |