Skip to main content

A merge conflict-less solution to committing an encrypted configuration to the repo with secrets and non-secrets side-by-side.

Project description

Quick start

This package features an opinionated configuration management system, focused on combining both secret and non-secret keys in the same configuration file. The values for secret keys are encrypted and can be committed to the repo, but since each key is separated on a line-by-line basis, merge conflicts shouldn't cause much trouble.

This package is intended to be used with a django project, though it's currently not making use of any Django specific features.

Needless to say, this is in very early development.

Install

pip install django-configuration-management

cli

Generate a key

In a terminal, enter:

generate_key

Follow the instructions printed to the console. For example, if you're setting up a production configuration, make a file called .env-production in the root of your django project. Inside of it, save the key generated above to a variable called ENC_KEY.

Upsert a secret

To insert or update a secret, enter:

upsert_secret --environment <your environment>

And follow the prompts.

Insert a non-secret

Simply open the .yml file for the generated stage (the naming scheme is config-<environment>.yaml), and insert a row. It should look like this:

USERNAME: whatsup1994 # non-secret
PASSWORD:
  secret: true
  value: gAAAAABf2_kxEgWXQzJ0SlRmDy6lbXe-d3dWD68W4aM26yiA0EO2_4pA5FhV96uMWCLwpt7N6Y32zXQq-gTJ3sREbh1GOvNh5Q==

Manually editing the file

You can change the values of non-secrets by hand, as well as the keynames, but clearly you must not change the value of secrets by hand, as they're encrypted. Changing the order of any of the keys is perfectly fine.

Print secrets to the console

To show the decrypted values of all the secrets in the console, enter:

reveal_secrets --environment <your-environment>

Re-encrypt a config file

To re-encrypt all secret values for a given environment's config file, pass

reencrypt --environment <your-environment> --new-key <your-new-key>

If you do not provide a key, a new one will be generated for you.

Extras

In the root of your django project, you can create a file called config-required.json.

The JSON object can be a list or a dictionary. This is useful for validating the presence of your keys on start-up.

Settings

There are two ways to use this library, if you don't mind a little magic, you can simply inject the config by importing the following function in your django settings file, and passing in the current module.

# settings.py
from django_configuration_management import inject_config

# development is the environment name
inject_config("development", sys.modules[__name__])

See the example project for a demonstration of this.

If you want more verbosity, you can import the following function which will return the config as a normalized dictionary that's flat and has all secrets decrypted.

# settings.py
from django_configuration_management import get_config

# config = {"USERNAME": "helloworld", "PASSWORD": "im decrypted}
config = get_config("development")

USERNAME = config["USERNAME"]
# ...

Using without a .env

If you want to skip using the .env, you can set the optional argument dotenv_required to False when invoking either of the above two methods. Doing so means it then becomes your responsibility to load an environment variable called ENC_KEY that stores the relevant encryption key for the stage you're trying to load.

# settings.py
from django_configuration_management import get_config

# Will error out if you didn't load ENC_KEY correctly
config = get_config("development", dotenv_required=False)

This project uses poetry for dependency management and packaging.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-configuration-management-0.2.2.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file django-configuration-management-0.2.2.tar.gz.

File metadata

File hashes

Hashes for django-configuration-management-0.2.2.tar.gz
Algorithm Hash digest
SHA256 631bc9716480eb7eb3f35e169db7f1efaf12b6f72bad1a4beb1fd0393e5903dd
MD5 6c0b4bb1b1f6ba8bedd1bb70f0f650eb
BLAKE2b-256 cc35648aebfaa9046b56b6efda402dd9b2335cce5aa2a96b8f35a7550e141703

See more details on using hashes here.

File details

Details for the file django_configuration_management-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_configuration_management-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 76cfa410120cb6e07cac945a4801a41c1ca6b86bc3a4587c6a34e080b30d9a4d
MD5 add009bff455a32882571c462514a4da
BLAKE2b-256 a6bd161cbd8694bcb4ba5f345636a8f13291b543d35e2188509890b0888ab7d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page