Sanitized sensitive information from your database dumps
Project description
django-sanitized-dump
Sanitize sensitive information from your database dumps 💩
Supports:
- PostgreSQL
- MySQL
Getting started
pip install django-sanitized-dump
orpip install django-sanitized-dump[MySQL]
if you use MySQL- Add
sanitized_dump
toINSTALLED_APPS
- Initialize config file:
./manage.py init_sanitizer
- Check your newly created
.sanitizerconfig
file and modify the sanitation strategy to fit your requirements. - Run
./manage.py check_sanitizerconfig
to verify that your.sanitizerconfig
includes all models and fields - Get sanitized database dump:
./manage.py create_sanitized_dump > dump.sql
DB Sanitation
Heavy lifting of the DB sanitation is done by: https://github.com/andersinno/python-database-sanitizer
Configuration
Configuration file is used to define a strategy on how to sanitize your data. Strategy defines a sanitation function for each model field.
Example config
config:
addons:
- "ai-sanitizers"
- "some-other-lib"
strategy:
user:
first_name: "name.first_name"
last_name: "name.last_name"
education:
created: null
modified: null
id: null
field: "education.field"
school: "education.school"
started: "datetime.datetime"
credits: null
information: "string.loremipsum_preserved"
file_file: null
Example custom sanitizers
# /sanitizers/name.py
def sanitize_first_name(value):
return faker.first_name()
def sanitize_last_name(value):
return faker.last_name()
# /sanitizers/education.py
def sanitize_field(value):
return "Some field"
def sanitize_schoo(value):
return "My school"
Validating sanitizer return value
Note: This should not be done in the initial implementation of the sanitizer but is up to the sanitizer functions. This is just a nice to have but not of a high priority.
Check that the returned value is of the same type as the argument value passed to the sanitizer. For instance, if a MySQL DATETIME value is passed to the sanitizer, a MySQL DATETIME value shoud be returned as well.
Configuration method resolution order
- Custom sanitizers inside ./sanitizers
- Addon sanitizers (
config.addons
) - Core sanitizers
Django Management Commands
Sanitized Dump
./manage.py create_sanitized_dump > dump.sql
- Warn about unhandled fields
- Creates a database dump (
mysqldump
/pgdump
) - Run sanitizer
Check Sanitized Dump
./manage.py check_sanitizerconfig
- Returns an error code if there are unhandled database fields
Check can be used in CI environments for detecting changes in models, that are not present in sanitizer configuration.
Init Sanitizer
./manage.py init_sanitizer
- Create configuration from current database state
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
File details
Details for the file django-sanitized-dump-1.2.2.tar.gz
.
File metadata
- Download URL: django-sanitized-dump-1.2.2.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.9.6 requests/2.27.1 setuptools/40.6.2 requests-toolbelt/1.0.0 tqdm/4.64.1 CPython/3.6.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | abb087a29b981de97d21bbac05c64f1f59ea0a69f479dde638994276499b4fd1 |
|
MD5 | 789882a792040023cd0683554af5c7f2 |
|
BLAKE2b-256 | 12024a20a30c8daf1ea7430674aa328cbe2a2334ba7ae24ade49eeccfd544d45 |
File details
Details for the file django_sanitized_dump-1.2.2-py2.py3-none-any.whl
.
File metadata
- Download URL: django_sanitized_dump-1.2.2-py2.py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.9.6 requests/2.27.1 setuptools/40.6.2 requests-toolbelt/1.0.0 tqdm/4.64.1 CPython/3.6.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77da860ca62f16869ad947f4da1d4823bac11ba4fcbb38cdcac69fd93e0f5a26 |
|
MD5 | ed25a7932365ea7848a1f5c351be3005 |
|
BLAKE2b-256 | 5bb763f41a15ee1bf8cb7c8b973e52a206f58130762772079f5bcdff1d1e1dea |