aboutsummaryrefslogtreecommitdiffstats
path: root/cli.py
blob: d59d9d280a66fe0d6c31488dedb9c978d957ef36 (plain)
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
41
42
43
44
45
46
47
import argparse
import json
from gdpr_obfuscator import Obfuscator

# This is a simple CLI for demonstration and doesn't undergo the same level
# of testing as the core library.


def main():
    parser = argparse.ArgumentParser(
        prog="GDPR-Obfuscator",
        description="Obfuscate sensitive data stored locally or in an AWS environment",
    )

    loc = parser.add_mutually_exclusive_group(required=True)
    loc.add_argument("-l", "--local", help="Local path to file")
    loc.add_argument("-s", "--s3", help="URI path to file stored in S3")

    parser.add_argument(
        "-p",
        "--pii",
        nargs="+",
        required=True,
        help="List of PII fields to obfuscate, separated by spaces",
    )

    args = parser.parse_args()

    obfuscator = Obfuscator()

    json_input = json.dumps(
        {
            "file_path": args.local if args.local else args.s3,
            "pii_fields": args.pii,
        }
    )

    if args.local and not args.s3:
        obfuscated_data = obfuscator.process_local(json_input)
    else:
        obfuscated_data = obfuscator.process_s3(json_input)

    print(obfuscated_data.decode("utf-8"))


if __name__ == "__main__":
    main()
git.ajschof.me — hosted by ajschofield — powered by cgit