forked from elastic/anonymize-it
-
Notifications
You must be signed in to change notification settings - Fork 0
/
anonymize.py
40 lines (31 loc) · 1.4 KB
/
anonymize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys
import json
from anonymize_it.anonymizers import Anonymizer
from anonymize_it.readers import reader_mapping
from anonymize_it.writers import writer_mapping
from anonymize_it import utils
import logging
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def read_config(config_file):
with open(config_file, 'r') as f:
config = json.load(f)
return config
if __name__ == "__main__":
logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p ->', level=logging.INFO)
logging.info("reading and parsing config file...")
config_file = sys.argv[1]
config = read_config(config_file)
config = utils.parse_config(config)
for conf in config._fields:
logging.info("{} = {}".format(conf, getattr(config, conf)))
logging.info("configuring reader...")
reader = reader_mapping[config.source['type']]
reader = reader(config.source['params'], config.masked_fields, config.suppressed_fields)
logging.info("configuring writer...")
writer = writer_mapping[config.dest['type']]
writer = writer(config.dest['params'])
logging.info("configuring anonymizer...")
anon = Anonymizer(reader=reader, writer=writer)
logging.info("performing anonymization...")
anon.anonymize(sensitive_fields=config.sensitive, infer=True, include_rest=config.include_rest, anonymization_type = config.anonymization_type)