PureVersation / src /safe_logging.py
GitHub Actions
Deploy backend from GitHub
a6ec759
Raw History Blame Contribute Delete
682 Bytes
"""Small helpers for operational logs that must not expose credentials."""
from urllib.parse import urlsplit
def redacted_endpoint(value) -> str:
raw = str(value or "").strip()
if not raw:
return "missing"
try:
parsed = urlsplit(raw)
if not parsed.scheme or not parsed.hostname:
return "configured (details redacted)"
host = parsed.hostname
if ":" in host and not host.startswith("["):
host = f"[{host}]"
port = f":{parsed.port}" if parsed.port is not None else ""
return f"{parsed.scheme}://{host}{port}"
except (TypeError, ValueError):
return "configured (details redacted)"