Spaces:
Running
Running
Download core/security/redaction.py from Alialdlfy1/Teleautoadminbot: direct link, hf CLI and curl.
- Browser
- Download file 632 Bytes
-
https://huggingface.co/spaces/Alialdlfy1/Teleautoadminbot/resolve/main/core/security/redaction.py
- Command line
-
hf download hf://spaces/Alialdlfy1/Teleautoadminbot/core/security/redaction.py
-
curl -L -o redaction.py https://huggingface.co/spaces/Alialdlfy1/Teleautoadminbot/resolve/main/core/security/redaction.py
632 Bytes
| from __future__ import annotations | |
| import re | |
| _SECRET_PATTERNS=( | |
| re.compile(r'(?i)(api[_-]?key|token|secret|password|credential)\s*[:=]\s*[^\s,;]+'), | |
| re.compile(r'(?i)bearer\s+[A-Za-z0-9._-]+'), | |
| ) | |
| def redact(text:str)->str: | |
| out=str(text) | |
| for p in _SECRET_PATTERNS: | |
| out=p.sub(lambda m: m.group(0).split(":")[0].split("=")[0]+"=<REDACTED>",out) | |
| return out | |
| def redact_mapping(mapping): | |
| if not isinstance(mapping, dict): | |
| return redact(mapping) | |
| return {k: ("<REDACTED>" if re.search(r'(?i)(api[_-]?key|token|secret|password|credential)', str(k)) else redact(v)) for k,v in mapping.items()} | |