# django-sanitized-dump
Sanitize sensitive information from your database dumps 💩
Supports:
- PostgreSQL
- MySQL
# Getting started
1. `pip install django-sanitized-dump` or `pip install django-sanitized-dump[MySQL]` if you use MySQL
2. Add `sanitized_dump` to `INSTALLED_APPS`
3. Initialize config file: `./manage.py init_sanitizer`
4. Check your newly created `.sanitizerconfig` file and modify the sanitation strategy to fit your requirements.
5. Run `./manage.py check_sanitizerconfig` to verify that your `.sanitizerconfig` includes all models and fields
6. 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
```yaml
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
```python
# /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
1. Custom sanitizers inside ./sanitizers
2. Addon sanitizers (`config.addons`)
3. Core sanitizers
### Django Management Commands
#### Sanitized Dump
`./manage.py create_sanitized_dump > dump.sql`
1. Warn about unhandled fields
2. Creates a database dump (`mysqldump`/`pgdump`)
3. Run sanitizer
#### Check Sanitized Dump
`./manage.py check_sanitizerconfig`
1. 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`
1. Create configuration from current database state
Raw data
{
"_id": null,
"home_page": "https://github.com/andersinno/django-sanitized-dump",
"name": "django-sanitized-dump",
"maintainer": "Anders Innovations",
"docs_url": null,
"requires_python": "",
"maintainer_email": "support@anders.fi",
"keywords": "django,database,sanitization,anonymization",
"author": "",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/12/02/4a20a30c8daf1ea7430674aa328cbe2a2334ba7ae24ade49eeccfd544d45/django-sanitized-dump-1.2.2.tar.gz",
"platform": "any",
"description": "# django-sanitized-dump\nSanitize sensitive information from your database dumps \ud83d\udca9\n\nSupports:\n- PostgreSQL\n- MySQL\n\n# Getting started\n\n1. `pip install django-sanitized-dump` or `pip install django-sanitized-dump[MySQL]` if you use MySQL\n2. Add `sanitized_dump` to `INSTALLED_APPS`\n3. Initialize config file: `./manage.py init_sanitizer`\n4. Check your newly created `.sanitizerconfig` file and modify the sanitation strategy to fit your requirements.\n5. Run `./manage.py check_sanitizerconfig` to verify that your `.sanitizerconfig` includes all models and fields\n6. Get sanitized database dump: `./manage.py create_sanitized_dump > dump.sql`\n\n# DB Sanitation\n\nHeavy lifting of the DB sanitation is done by: https://github.com/andersinno/python-database-sanitizer\n\n### Configuration\n\nConfiguration file is used to define a strategy on how to sanitize your data. Strategy defines a sanitation function for each model field.\n\n#### Example config\n```yaml\nconfig:\n addons:\n - \"ai-sanitizers\"\n - \"some-other-lib\"\nstrategy:\n user:\n first_name: \"name.first_name\"\n last_name: \"name.last_name\"\n education:\n created: null\n modified: null\n id: null\n field: \"education.field\"\n school: \"education.school\"\n started: \"datetime.datetime\"\n credits: null\n information: \"string.loremipsum_preserved\"\n file_file: null\n```\n\n#### Example custom sanitizers\n```python\n# /sanitizers/name.py\ndef sanitize_first_name(value):\n return faker.first_name()\n\ndef sanitize_last_name(value):\n return faker.last_name()\n\n# /sanitizers/education.py\ndef sanitize_field(value):\n return \"Some field\"\n\ndef sanitize_schoo(value):\n return \"My school\"\n```\n\n#### Validating sanitizer return value\n\n> 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.\n\nCheck that the returned value is of the same type as the argument value passed to the sanitizer.\nFor instance, if a MySQL DATETIME value is passed to the sanitizer, a MySQL DATETIME value shoud be returned as well.\n\n\n#### Configuration method resolution order\n\n1. Custom sanitizers inside ./sanitizers\n2. Addon sanitizers (`config.addons`)\n3. Core sanitizers\n\n### Django Management Commands\n\n#### Sanitized Dump\n\n`./manage.py create_sanitized_dump > dump.sql`\n\n1. Warn about unhandled fields\n2. Creates a database dump (`mysqldump`/`pgdump`)\n3. Run sanitizer\n\n\n#### Check Sanitized Dump\n\n`./manage.py check_sanitizerconfig`\n\n1. Returns an error code if there are unhandled database fields\n\nCheck can be used in CI environments for detecting changes in models, that are not present in\nsanitizer configuration.\n\n\n#### Init Sanitizer\n\n`./manage.py init_sanitizer`\n\n1. Create configuration from current database state\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Sanitized sensitive information from your database dumps",
"version": "1.2.2",
"project_urls": {
"Homepage": "https://github.com/andersinno/django-sanitized-dump"
},
"split_keywords": [
"django",
"database",
"sanitization",
"anonymization"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5bb763f41a15ee1bf8cb7c8b973e52a206f58130762772079f5bcdff1d1e1dea",
"md5": "ed25a7932365ea7848a1f5c351be3005",
"sha256": "77da860ca62f16869ad947f4da1d4823bac11ba4fcbb38cdcac69fd93e0f5a26"
},
"downloads": -1,
"filename": "django_sanitized_dump-1.2.2-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "ed25a7932365ea7848a1f5c351be3005",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 10395,
"upload_time": "2023-09-20T14:14:30",
"upload_time_iso_8601": "2023-09-20T14:14:30.100385Z",
"url": "https://files.pythonhosted.org/packages/5b/b7/63f41a15ee1bf8cb7c8b973e52a206f58130762772079f5bcdff1d1e1dea/django_sanitized_dump-1.2.2-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "12024a20a30c8daf1ea7430674aa328cbe2a2334ba7ae24ade49eeccfd544d45",
"md5": "789882a792040023cd0683554af5c7f2",
"sha256": "abb087a29b981de97d21bbac05c64f1f59ea0a69f479dde638994276499b4fd1"
},
"downloads": -1,
"filename": "django-sanitized-dump-1.2.2.tar.gz",
"has_sig": false,
"md5_digest": "789882a792040023cd0683554af5c7f2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9398,
"upload_time": "2023-09-20T14:14:31",
"upload_time_iso_8601": "2023-09-20T14:14:31.954363Z",
"url": "https://files.pythonhosted.org/packages/12/02/4a20a30c8daf1ea7430674aa328cbe2a2334ba7ae24ade49eeccfd544d45/django-sanitized-dump-1.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-20 14:14:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "andersinno",
"github_project": "django-sanitized-dump",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "django-sanitized-dump"
}