diff options
| author | Alex <git@ajschof.me> | 2025-02-17 16:47:47 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-17 16:47:47 +0000 |
| commit | 00917b8ecf67de9e955479be555d74fcc8257020 (patch) | |
| tree | 17dd9b2e85866f85bdbb3702185463b13c911a28 /obfuscator/obfuscate.py | |
| parent | bf323b8c2ebd47bb446ba773027f389a0887e325 (diff) | |
| parent | e2b0f2553b8dfcbe39f6e6fdc86ca68cc63f5705 (diff) | |
| download | gdpr-obfuscator-00917b8ecf67de9e955479be555d74fcc8257020.tar.gz gdpr-obfuscator-00917b8ecf67de9e955479be555d74fcc8257020.zip | |
Merge pull request #3 from ajschofield/add-docs
update README & add comments in src code
Diffstat (limited to 'obfuscator/obfuscate.py')
| -rw-r--r-- | obfuscator/obfuscate.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/obfuscator/obfuscate.py b/obfuscator/obfuscate.py index ac0bd21..3da9155 100644 --- a/obfuscator/obfuscate.py +++ b/obfuscator/obfuscate.py @@ -1,16 +1,24 @@ from typing import List, Dict from obfuscator.logger import get_logger +# Create the logger logger = get_logger("Obfuscator") - def obfuscate( data: List[Dict[str, str]], pii_fields: List[str] ) -> List[Dict[str, str]]: + """ + A function to obfuscate PII fields in a list of dictionaries, replacing + sensitive values with a string of asterisks. + """ + # If no data is provided, log a message and return an empty list if not data: logger.info("No valid data was provided to obfuscate") return [] + # Obfuscate the PII fields in each record using a list/dict comprehension + # This code is good but makes debugging a bit tricky. I may consider + # breaking it down into a for loop. return [ {k: ("***" if k in pii_fields else v) for k, v in record.items()} for record in data |
