Files
VPNaaS-Migrator/ipsec_migrator/redact.py
T

25 lines
771 B
Python
Raw Normal View History

2026-07-21 15:05:52 +03:00
"""PSK redaction for safe logging.
Walks any nested dict/list structure and blanks out the value of any dict
key literally named "psk" (Neutron's and Sprut's shared field name) when
that value is not null. Used only for logging -- the real value is always
used wherever the original object is read for actual API calls/storage.
"""
from __future__ import annotations
from typing import Any
_PSK_KEYS = {"psk"}
_REDACTED = "***REDACTED***"
def redact_psk(value: Any) -> Any:
if isinstance(value, dict):
return {
key: (_REDACTED if key in _PSK_KEYS and val is not None else redact_psk(val))
for key, val in value.items()
}
if isinstance(value, list):
return [redact_psk(item) for item in value]
return value