Skip to main content

A python library to decrypt config-yourself files

Project description

config-yourself-python

CircleCI Documentation Status

config-yourself is a python 2.7+ package to help your application read go-config-yourself files.


Installation

# choose if you'd like to use `kms`, `gpg` or the `password` provider
pip install 'config_yourself[kms]'

# or go crazy with all of them
pip install 'config_yourself[all]'

# with pipenv
pipenv install 'config_yourself[kms]'

# with poetry
poetry add config_yourself --extras kms

Usage

Here's how to work with config_yourself in python:

Basic usage

import config_yourself as cy

# Load one config file
encrypted_config = cy.load.file("config/test.yml")
config = cy.Config(encrypted_config)
# now use it like a dict, all secrets have been decrypted
print(config["database"])

Complete usage

# Let's get a little more creative
# `config_yourself` can take a number of config files, merge, and decrypt them

# we start with a defaults file, that defines the valid keys for all subsequent files
# then, we take a file path provided from the environment
files = ['config/defaults.yml', os.environ['CONFIG_FILE']]

# During development, we might choose to have a SCM-ignored personal file, to apply overrides to our personal taste
if os.path.exists(personal_config_path):
  files.append('config/personal.yml')

# we take every file, deserialize it from YAML
configs = [cy.load.file(path) for path in files]
# we can also append regular dicts to this list
configs.append({
  'MODE': os.environ.get('BACKEND_MODE', 'tripolar')
})

# we can also decide to override values straight from the environment...
if os.environ['SHOOT_MYSELF_IN_THE_FOOT']:
  # config_yourself will parse env values as JSON, so this will turn to False
  os.environ['CONFIG.someService.enabled'] = 'false'
  configs.append(cy.load.env('CONFIG'))

# Take our list of configs, and pass secrets to the decryption provider
config = cy.Config(*configs, secrets={'password': os.environ['SUPER_SECRET_PASSWORD']})
# The resulting merged config is finally decrypted

print(config['someService']['endpoint']) # => "https://super-secure-service.example.com"
print(config['someService']['enabled']) # => False

From a Django or Flask application

When using in Flask or Django and you'd like to follow the same pattern above, use the :py:meth:~config_yourself.AppConfig method instead:

import config_yourself as cy

# Use AppConfig
config = cy.AppConfig()
# functionally equal to:

# Remember to set CONFIG_FILE=./config/production.yml
cy.Config(**[
  "./config/defaults.yml",
  "./config/production.yml",
])

# assuming CONFIG_FILE="" and an existing "personal.yml" file
cy.Config(**[
  "./config/defaults.yml",
  "./config/local.yml",
  "./config/personal.yml",
])

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

config-yourself-1.0.2.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

config_yourself-1.0.2-py2.py3-none-any.whl (23.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file config-yourself-1.0.2.tar.gz.

File metadata

  • Download URL: config-yourself-1.0.2.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9

File hashes

Hashes for config-yourself-1.0.2.tar.gz
Algorithm Hash digest
SHA256 9de174052a7ea66e9e43f8fafec0485e5f3cb5b065bed4628df8e603b6efbeff
MD5 1ca257c525c21d64ee96351f94bf38b9
BLAKE2b-256 e5ebfcca514b15da459b632c4fef1f40e746703ba2a88c256aa08a56212680f4

See more details on using hashes here.

File details

Details for the file config_yourself-1.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: config_yourself-1.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9

File hashes

Hashes for config_yourself-1.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3427dfa6d1969b1fd625c9b2b4252545af462dd9d60d0b9d530f8eee37845ca9
MD5 41c0adca9db5f7eae32f52753601509c
BLAKE2b-256 7421ed9707fbbf454c86f6bf53b4c466ae9989cb9f42b469eef17bfe26dbe4ef

See more details on using hashes here.

Supported by

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