A module for obfuscating a mysqldump file
Project description
Py_Obfuscate
A module for obfuscating a mysqldump file
This project is a partial-port of My_Obfusicate. Under the hood it mostly uses Faker for generating fake data.
Example usage
This package exposes a py_obfuscate module which contains Obfuscator class with a very simple inteface.
It's obfuscate method expects two streams: a read string (e.g. the mysqldump file) and write stream (e.g. the file to write the obfuscated dump to).
obfuscatator.obfuscate(streamIn, streamOut)
As a more practical example, create the file obfuscate.py
import sys
import yaml
import py_obfuscate
config = yaml.safe_load(open("obfuscator.yaml"))
obfuscatator = py_obfuscate.Obfuscator(config)
src = sys.stdin
out = sys.stdout
obfuscatator.obfuscate(src, out)
Now create a config file (obfuscate.yaml), e.g.:
tables:
users:
name:
type: "name"
email:
type: "email"
accountno:
type: "string"
chars: "1234567890"
length: 10
You should change this config to reflect the tables and columns you wish to obfuscate.
Now you can run:
mysqldump -c --add-drop-table --hex-blob -u user -ppassword database | python obfuscate.py > obfuscated_dump.sql
Note that the -c option on mysqldump is required to use py_obfuscate. Additionally, the default behavior of mysqldump is to output special characters. This may cause trouble, so you can request hex-encoded blob content with –hex-blob. If you get MySQL errors due to very long lines, try some combination of –max_allowed_packet=128M, –single-transaction, –skip-extended-insert, and –quick.
Configuration
In the above example we've used YAML as the configuration format; since you pass py_obfuscate.Obfuscator a config object (dictionary) you can
use any format you wish, so long as parses into the same structure. The basic structure is:
locale: <local string (optional): defaults "en_GB">
tables:
<table>:
truncate: <boolean - set to true to remove insert for this table. Defaults `false`>
<column>:
type: <type - how to obfusciate this column>
<type-specific-option>: <type-specific-option-value>
Tables or columns which are ommitted from the config are ignored. Currently no warning is given.
Locale
- type: string
- default:
"en_GB"
This is the locale string passed to Faker.
Truncate
Setting truncate: true for a table will remove the insert from the mysqldump.
Types
These are the following types supported:
string
Options:
chars(string) The character list to choose from (defaults"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_+-=[{]}/?|!@#$%^&*()``~")length(integer) The length of the string (defaults10)
fixed
Options:
value(string|array) Replace column entries with this value or one of the values in the specified array (defaults"")
integer
Options:
min(string) Replace column entries with a random integer greater than or equal to this value (defaults0)max(string) Replace column entries with a random integer less than or equal to this value (defaults100)
name
first_name
last_name
username
address
street_address
secondary_address
city
postcode
company
ip
url
sortcode
bank_account
mobile
uk_landline
null
Unit testes
python -m unittest discover -s py_obfuscate
License
This work is provided under the MIT License. See the included LICENSE file.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_obfuscate-0.1.6.tar.gz.
File metadata
- Download URL: py_obfuscate-0.1.6.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fb008498f16d80fe793ad96525855732614d09c0378abbee1bfe6b2551b96b7
|
|
| MD5 |
7253bb802d7e043ab563df5096d080e7
|
|
| BLAKE2b-256 |
4638979afc68fffdcb5a96f02032ccf24946bf0691042d687386fef20dfacf41
|
File details
Details for the file py_obfuscate-0.1.6-py3-none-any.whl.
File metadata
- Download URL: py_obfuscate-0.1.6-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99ade377b602e977781468e9eb979bdb35d84e4c58a91f05aca9a18eadf43e4b
|
|
| MD5 |
0b2b5a260f6479b3417441dd66abb197
|
|
| BLAKE2b-256 |
7ef75bb147ca9e5242bec4cfa7cb9212a849b06e241304f68b92df8a075f5848
|