def _is_secret_key(key):
    k = str(key).lower()
    return ('password' in k) or ('token' in k) or ('secret' in k)


def _redact(value):
    if isinstance(value, dict):
        new = {}
        for k, v in value.items():
            if _is_secret_key(k):
                new[k] = '[REDACTED]'
            else:
                new[k] = _redact(v)
        return new
    if isinstance(value, list):
        return [_redact(v) for v in value]
    return value


def redact_secrets(value):
    return _redact(value)
