Skip to content

Commit ceeb5df

Browse files
committed
Redact id in rest request header
1 parent f75e7ef commit ceeb5df

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/homematicip/connection/rest_connection.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,15 @@ async def async_post(self, url: str, data: dict | None = None, custom_header: di
8282
"""
8383
full_url = self._build_url(self._context.rest_url, url)
8484
try:
85+
data_logging = data.copy() if data is not None else {}
86+
if "id" in data_logging:
87+
data_logging["id"] = "REDACTED"
88+
8589
header = self._headers
8690
if custom_header is not None:
8791
header = custom_header
8892

89-
LOGGER.debug(f"Sending post request to url {full_url}. Data is: {data}")
93+
LOGGER.debug(f"Sending post request to url {full_url}. Data is: {data_logging}")
9094
r = await self._execute_request_async(full_url, data, header)
9195
LOGGER.debug(f"Got response {r.status_code}.")
9296

@@ -109,7 +113,7 @@ async def async_post(self, url: str, data: dict | None = None, custom_header: di
109113
except httpx.HTTPStatusError as exc:
110114
if self._log_status_exceptions:
111115
LOGGER.error(
112-
f"Error response {exc.response.status_code} ({exc.response.text}) while requesting {exc.request.url!r} with data {data if data is not None else "<no-data>"}."
116+
f"Error response {exc.response.status_code} ({exc.response.text}) while requesting {exc.request.url!r} with data {data_logging if data_logging is not None else "<no-data>"}."
113117
)
114118
return RestResult(status=exc.response.status_code, exception=exc, text=exc.response.text)
115119

0 commit comments

Comments
 (0)