diff options
| author | Alex Schofield <git@ajschof.me> | 2025-02-20 18:27:12 +0000 |
|---|---|---|
| committer | Alex Schofield <git@ajschof.me> | 2025-02-20 18:27:12 +0000 |
| commit | 70a16769761450b9c2aa63cda86a30a73bc0217c (patch) | |
| tree | b9b86ac8575e12f30bc0e53233c94b4ab99973b6 /gdpr_obfuscator/obfuscate.py | |
| parent | 9827fcf1a40b0c4993da3f420177f4e390e038e9 (diff) | |
| download | gdpr-obfuscator-70a16769761450b9c2aa63cda86a30a73bc0217c.tar.gz gdpr-obfuscator-70a16769761450b9c2aa63cda86a30a73bc0217c.zip | |
update pyproject.toml & references with new src folder name
Diffstat (limited to 'gdpr_obfuscator/obfuscate.py')
| -rw-r--r-- | gdpr_obfuscator/obfuscate.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/gdpr_obfuscator/obfuscate.py b/gdpr_obfuscator/obfuscate.py new file mode 100644 index 0000000..cd12b6d --- /dev/null +++ b/gdpr_obfuscator/obfuscate.py @@ -0,0 +1,26 @@ +from typing import List, Dict +from obfuscator.logger import get_logger + +logger = get_logger("OBFUSCATE") + + +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 not data: + logger.error( + "Invalid or empty data was provided to obfuscate. Returning empty list." + ) + return [] + if not pii_fields: + logger.error("No PII fields provided to obfuscate. Returning data unchanged.") + return data + + return [ + {k: ("***" if k in pii_fields else v) for k, v in record.items()} + for record in data + ] |
