Creates a pg_dumpish output which masks data without saving changes to the source database.
Project description
Django Mask Postgres Data
Adds a management command to your Django project which allows you to create a (sort of) pg_dump of your data with sensitive data masked.
Installation
Install with pip:
pip install django-maskpostgresdata
And add maskpostgresdata
to your INSTALLED_APPS
:
INSTALLED_APPS = [
...
'maskpostgresdata',
...
]
Usage
By default, django-maskpostgresdata
will replace the password
column for each row in the Django User
model with "password". Just run manage.py dump_masked_data
and you'll get a pg_dump with the password field changed to "password" for all users.
There are 2 ways to customise the behaviour of django-maskpostgresdata
.
To override individual fields of a model with a given value, add a dictionary called MASKER_FIELDS
to your settings using the following format:
MASKER_FIELDS = {
"{ APP_NAME }": {"{ MODEL_NAME }": {"{ FIELD_NAME }": { VALUE },}},
}
Alternatively, you can define exactly how the data is updated by subclassing BasePostgresDataMaskingCommand
in a management command of your own. For example:
from django.contrib.auth.hashers import make_password
from maskpostgresdata import BasePostgresDataMaskingCommand
class Command(BasePostgresDataMaskingCommand):
def update_auth_user(self, queryset):
queryset.update(password=make_password("a_different_password"))
Just create a method called update_{ db_table_name }
taking a queryset
as the parameter. You can then perform update
operations on this queryset. { db_table_name }
is of the format {app_label}_{model_name}
by default, but could technically be different.
You can then run manage.py dump_masked_data
and it will dump your data to stdout
.
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
Hashes for django-maskpostgresdata-0.1.16.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f67ecd6f372ef5d891295bd5f65f18c636f0dc716ac4e897b64e4ba6f63dd50e |
|
MD5 | 5f32b6b5f221bafd7803465df0b736b9 |
|
BLAKE2b-256 | b473cf00c7a4f0e392d320c1335c7f01d8987453a4519c953bb8a1c1ecb5caab |
Hashes for django_maskpostgresdata-0.1.16-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2124d724f452f71b7c729284efbcf2a75ee0b6ec6e8eae563df5242d21b1ff5e |
|
MD5 | 62857b6b80de7caf1862738ba1a6e2f7 |
|
BLAKE2b-256 | 83a5bb28285e70096e2f45408f5ba139b2331eab90f3aa89431008b2dfe5103e |