Provide settings to Django from a secret store such as Google Cloud Secrets
Project description
Yet Another Django Settings Helper
This library allows secret settings to be easily changed for dev/Staging/Production etc purposes. e.g. One might obtain development settings from the process environment but later deploy to Google Compute Engine where use of Google Secret Manager is recommended. If the app later finds its way onto AWS, a suitable fetcher can be installed or written.
I tend to put all the secret settings for an environment in a single secret as a JSON document, for cost and convenience. You can also put non-secret settings in the same document or install them as environment variables as you prefer.
Installation
pip install dj_secret_settings
Configuration
Install settings fetchers to get the raw data from the store, and settings stores to make sense of the raw data and return pieces of it on demand.
The package can be configured with a string or by using the environment variable DJ_SECRET_SETTINGS_URL
with the form:
store_type+fetcher_type://information.used.by/the/fetcher/and/or/the/store_type?like_a=url
e.g. json+gsm://anything-here-perhaps-service-account/projects/123456789/secrets/my-secret/versions/42
indicates that data will be fetched from Google Secret Manager* and interpreted as a JSON string.
* configuration of this is obviously required too, contact me if you need help with that.
The package includes a Google Secret Manager fetcher, with JSON and environment variable store types. These can be overridden by installing a root package of the form dj_secret_settings_{store_type} (e.g. dj_secret_settings_json) or dj_secret_settings_{fetcher_type} (e.g dj_secret_settings_gsm). Alternatively you can install differently named root packages and modifiy the URL (e.g dj_secret_settings_yaml for a yaml store using the URL of the form yaml+gsm://...).
Usage
from dj_secret_settings import settings_store
store = settings.store.load("json+gsm://anything-here-perhaps-service-account/projects/123456789/secrets/my-secret/versions/42")
MAX_SIZE = store.get_value('MAX_SIZE', default=314, coerce_type=int)
IS_PRODUCTION = store.get_boolean('is_production', default=FALSE)
MY_LIST = store.get_array('MY_LIST')
A_MAP = store.get_mapping('A_MAP', default={})
default
s are always optional, as is coerce_type
on get_value
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 dj_secret_settings-0.1.0a1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5dba9d31e2a65a2877e31d1b095559177c21a383ba6f602490cb63dfcc014e9 |
|
MD5 | 7cef814a09556ed8b1137a8b51dfe08f |
|
BLAKE2b-256 | 1e6a296abd8c0f49d383095605106ada484aeeb492b1e2195420257a58d347a5 |
Hashes for dj_secret_settings-0.1.0a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dc3c3f43cac94cc55120ba0bb90889f20f84d513c5b0d12938dbfd3944863e6 |
|
MD5 | a22bddd41e3475308ebce15c5cc4d085 |
|
BLAKE2b-256 | 6d2fce1672ae7eabbf6a4dc781f55a25dac4438e9f29dc74337cebe486cbf16a |