An environment manager for Flask, with support for whitelists and AWS SSM.
Project description
Flask Environment Manager
A Flask environment manager for copying parameters from a source into the Flask app config, while also abiding by an override whitelist.
Currently, this packaged supports overriding the config from:
os.environ
viaOsEnvironmentManager
AWS SSM
viaSsmEnvironmentManager
Installation
Install and update using pip
:
pip install -U flask-environment-manager
Getting Started
Before using the Environment Manager, you must ensure the following is set up in your Flask app config:
- ENV_OVERRIDE_WHITELIST
Example
{
"ENV_OVERRIDE_WHITELIST": [
"ENV_VAR_1",
"ENV_VAR_2",
"ENV_VAR_3",
"ENV_VAR_4"
],
}
The keys stored in the whitelist will be the only keys updated in the config.
Managers
SSM Environment Manager
This manager can be imported with from flask_environment_manager import SsmEnvironmentManager
This manager requires the following to be definied in the Flask app config, in addition the the whitelist:
- AWS_SSM_ACCESS_KEY
- AWS_SSM_ACCESS_SECRET
- AWS_SSM_REGION
This manager will connect to AWS SSM and get parameters from a given path.
The following snippet will load all parameters nested under the /directory
path (recursively).
from flask_environment_manager import SsmEnvironmentManager
manager = SsmEnvironmentManager(app, "/directory")
manager.load_into_config()
It is important to note that parameters are stored as their final name in the path. For example, the parameter stored at /directory/params/param
will be stored as param
.
OS Environment Manager
This manager can be imported with from flask_environment_manager import OsEnvironmentManager
This manager will use the os.environ
keys and values to update the app.config
from flask_environment_manager import OsEnvironmentManager
manager = OsEnvironmentManager(app)
manager.load_into_config()
Developing
The build pipeline requires your tests to pass and code to be formatted
Make sure you have Python 3.x installed on your machine (use pyenv).
Install the dependencies with pipenv (making sure to include dev and pre-release packages):
pipenv install --dev --pre
Configure your environment:
pipenv shell && export PYTHONPATH="$PWD"
Run the tests:
pytest
Or with logging:
pytest -s
Or tests with coverage:
pytest --cov=./
Format the code with Black:
black $PWD
Releases
Cleanup the (.gitignored) dist
folder (if you have one):
rm -rf dist
Notch up the version number in setup.py
and build:
python3 setup.py sdist bdist_wheel
Push to PyPi (using the ScholarPack credentials when prompted)
python3 -m twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
Links
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
Built Distribution
Hashes for flask-environment-manager-2.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 907fb4d07c5394674111f53bbbabb3a2044ac48e9a24169aa742e7f986719ed6 |
|
MD5 | 53135c7385c3411540ff359d7efdb909 |
|
BLAKE2b-256 | 59fba9c56125b024c6bb48424233161b4641bcab87fc3ca3f4e7d1273bf98f37 |
Hashes for flask_environment_manager-2.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d914919bdd85a8466e789686d50fd238229163244ce8ce85429c25dd8e5d2ad |
|
MD5 | a452115bad8317a3ead702fe9d96b7dc |
|
BLAKE2b-256 | 8d806814c5e2c6f6823c282aa0206bdcc31a19aa81e1b9fb8df3111d0a954579 |