DJANGO OUTBOX ENCRYPTION
Sometimes, when you ready to publish your project to server.
There is a slight change between the application settings on the local and the server. Such as database name, password, etc. The second thing, is you need to encrypt information like password or other. The last one, you need to automatically select setting local when you work on local computer, and auto select server when application running on server.
You are on the right path...
Install package to your environment
> pip install outbox-encryption
How it works
On developing time, library will scan your environment variable
to get file name specific for you computer, for example : .env-outbox-python
this file must exists on your source code to make application continue.
On deploy time, for example your local computer, library again will scan your
environment variable and get file name base on computer where it running
if file found, application continue, else stop application
if you ready to deploy to server, just rename file .env-outbox-python to name
which is must be found on server
How to use
Create Encrypt File
> python manage.py shell
> from encryption import OutboxEncryption
> lib = OutboxEncryption()
> mplaint_text = {
'DB_PASSWORD': '',
'SECRET_KEY': 'xxg_7me8rl2m#a_h2oresgt2#ni=3_4*!ai*=rtsq)yi!g7_5-51xx'
}
> lib.enc_environ(mplaint_text)
# new file is created (maybe file is hidden, CTRL+H to show it)
# Open new file that recently created
You have to write other setting that no encrypt apply, such as:
DEBUG=True
UNDER_CONSTRUCTION=False
DB_ENGINE=django.db.backends.mysql
DB_NAME=db_name
DB_USER=root
DB_HOST=127.0.0.1
DB_PORT=3306
Note:
File name auto create base on environment variable on running computer.
If run on server just rename this file, and write setting needed to run website on server
Decrypt environment file
> python manage.py shell
> from encryption import OutboxEncryption
> lib = OutboxEncryption()
> mplaint_key = {
'DB_PASSWORD',
'SECRET_KEY'
}
> mplaint_list = {
'ALLOWED_HOSTS',
'CSRF_TRUSTED_ORIGINS'
}
> key = lib.dec_environ(mplaint_key, mplaint_list)
> print (key)
Change your settings.py file
# Write inside settings.py (django project settings):
> from encryption import OutboxEncryption
> lib = OutboxEncryption()
# List of key variable that must be encrypt or decrypt before set or get data
> mplaint_key = ['DB_PASSWORD', 'SECRET_KEY']
Variable that must be cast as list from environmnet to settings.py
> mplaint_list = ['ALLOWED_HOSTS', 'CSRF_TRUSTED_ORIGINS']
Variable that must be cast as tuple from environment to settings.py
> mplaint_tuple = ['SECURE_PROXY_SSL_HEADER']
Get encryption data
> key = lib.decrypt_environ(mplaint_key, mplaint_list, mplaint_tuple)
Setting variable :
> DEBUG = key['DEBUG']
> UNDER_CONSTRUCTION = key['UNDER_CONSTRUCTION']
> DEBUG = key['DEBUG']
> SECRET_KEY = key['SECRET_KEY']
> ALLOWED_HOSTS = key['ALLOWED_HOSTS']
> tmp_engine = key['DB_ENGINE']
> if 'sqlite3' in tmp_engine:
DATABASES = {
'default': {
'ENGINE': tmp_engine,
'NAME': key['DB_NAME'], # complete path
}
}
> else: # default
> DATABASES = {
'default': {
'ENGINE' : key['DB_ENGINE'],
'NAME' : key['DB_NAME'],
'USER' : key['DB_USER'],
'PASSWORD' : key['DB_PASSWORD'],
'HOST' : key['DB_HOST'],
'PORT' : key['DB_PORT'],
}
> SECURE_PROXY_SSL_HEADER = key['SECURE_PROXY_SSL_HEADER']
# Optional:
> tmp = key.get('CSRF_TRUSTED_ORIGINS')
> if tmp:
> CSRF_TRUSTED_ORIGINS=key['CSRF_TRUSTED_ORIGINS']
# # use default value if setting not exists
> tmp = key.get('STATIC_ROOT') # True if exists, None if not exists
> STATIC_ROOT = key['STATIC_ROOT'] if tmp else os.path.join(BASE_DIR, 'staticfiles')
> tmp = key.get('MEDIA_ROOT')
> MEDIA_ROOT = key['MEDIA_ROOT'] if tmp else os.path.join(BASE_DIR, 'media')
Metadata
Release files for outbox-encryption 1.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| outbox_encryption-1.1.6.tar.gz | 14.2 kB | Without provenance | Details for outbox_encryption-1.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| outbox_encryption-1.1.6-py3-none-any.whl | Python 3 | none | any | Details for outbox_encryption-1.1.6-py3-none-any.whl |
Total release size: 26.4 kB
Release files / outbox_encryption-1.1.6.tar.gz
| Download URL | outbox_encryption-1.1.6.tar.gz |
|---|---|
| Size | 14.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bef1b38c3afaaabcec846646691f3555e269db9fd2f722080197e18ecb2ddaa8
|
|
BLAKE2b-256 checksum How to use checksums |
018bed126dcf78ac94c34cf3c278d91618db042884161a5bb2a6db5a6d328a6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Release files / outbox_encryption-1.1.6-py3-none-any.whl
| Download URL | outbox_encryption-1.1.6-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a29a76971d720b21c976cbdf9bdb129dbdeec171d0820020e23f025aa9e1408
|
|
BLAKE2b-256 checksum How to use checksums |
739b972b31c7c7621f7caca4c679ec9cde7934d204a521983e81f327502f5981
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Security for outbox-encryption 1.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.