diff options
| author | Alex Schofield <git@ajschof.me> | 2025-02-17 14:55:53 +0000 |
|---|---|---|
| committer | Alex Schofield <git@ajschof.me> | 2025-02-17 14:55:53 +0000 |
| commit | 3837fb40c1f70fa8bfd65872cc1c85963903fe3a (patch) | |
| tree | e8fb7029ab91da25c8d14fb2409fbdd29baa3333 /obfuscator | |
| parent | de33c0c98201a275244a71826d11bb8ee3a12245 (diff) | |
| download | gdpr-obfuscator-3837fb40c1f70fa8bfd65872cc1c85963903fe3a.tar.gz gdpr-obfuscator-3837fb40c1f70fa8bfd65872cc1c85963903fe3a.zip | |
add comments to obfuscate.py to explain code
Diffstat (limited to 'obfuscator')
| -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 |
