Redact sensitive info from debug logs (#1069)

Redacts sensitive data when debug logging device responses such as mac,
location and usernames
This commit is contained in:
Steven B.
2024-07-17 18:57:09 +01:00
committed by GitHub
parent c19389f236
commit c4f015a2fb
11 changed files with 300 additions and 39 deletions

View File

@@ -19,7 +19,6 @@ import logging
import socket
import struct
from collections.abc import Generator
from pprint import pformat as pf
# When support for cpython older than 3.11 is dropped
# async_timeout can be replaced with asyncio.timeout
@@ -78,9 +77,8 @@ class XorTransport(BaseTransport):
"""Execute a query on the device and wait for the response."""
assert self.writer is not None # noqa: S101
assert self.reader is not None # noqa: S101
debug_log = _LOGGER.isEnabledFor(logging.DEBUG)
if debug_log:
_LOGGER.debug("%s >> %s", self._host, request)
_LOGGER.debug("Device %s sending query %s", self._host, request)
self.writer.write(XorEncryption.encrypt(request))
await self.writer.drain()
@@ -90,8 +88,8 @@ class XorTransport(BaseTransport):
buffer = await self.reader.readexactly(length)
response = XorEncryption.decrypt(buffer)
json_payload = json_loads(response)
if debug_log:
_LOGGER.debug("%s << %s", self._host, pf(json_payload))
_LOGGER.debug("Device %s query response received", self._host)
return json_payload