Skip to content

Commit ed05bf1

Browse files
committed
refactor: improve logging messages for security
1 parent b841844 commit ed05bf1

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/mistapi/__api_session.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def _load_keyring(self, keyring_service) -> None:
285285
self.set_api_token(mist_apitoken)
286286
mist_user = keyring.get_password(keyring_service, "MIST_USER")
287287
if mist_user:
288-
LOGGER.info("apisession:_load_keyring: MIST_USER=%s", mist_user)
288+
LOGGER.info("apisession:_load_keyring: MIST_USER retrieved")
289289
self.set_email(mist_user)
290290
mist_password = keyring.get_password(keyring_service, "MIST_PASSWORD")
291291
if mist_password:
@@ -466,8 +466,8 @@ def set_email(self, email: str | None = None) -> None:
466466
self.email = email
467467
else:
468468
self.email = input("Login: ")
469-
LOGGER.info("apisession:set_email:email configured to %s", self.email)
470-
CONSOLE.debug("Email configured to %s", self.email)
469+
LOGGER.info("apisession:set_email:email configured")
470+
CONSOLE.debug("Email configured")
471471

472472
def set_password(self, password: str | None = None) -> None:
473473
"""
@@ -573,7 +573,10 @@ def _get_api_token_data(self, apitoken) -> tuple[str | None, list | None]:
573573
data.status_code,
574574
)
575575
CONSOLE.critical(
576-
f"Invalid API Token {apitoken[:4]}...{apitoken[-4:]}: status code {data.status_code}\r\n"
576+
"Invalid API Token %s...%s: status code %s\r\n",
577+
apitoken[:4],
578+
apitoken[-4:],
579+
data.status_code,
577580
)
578581
raise ValueError(
579582
f"Invalid API Token {apitoken[:4]}...{apitoken[-4:]}: status code {data.status_code}"
@@ -856,7 +859,7 @@ def login_with_return(
856859
LOGGER.info("apisession:login_with_return:access authorized")
857860
return {"authenticated": True, "error": ""}
858861
else:
859-
LOGGER.error("apisession:login_with_return:access denied: %s", resp.data)
862+
LOGGER.error("apisession:login_with_return:access denied: status code %s", resp.status_code)
860863
return {"authenticated": False, "error": resp.data}
861864

862865
def logout(self) -> None:
@@ -1057,7 +1060,8 @@ def _two_factor_authentication(self, two_factor: str) -> bool:
10571060
resp.status_code,
10581061
)
10591062
CONSOLE.error(
1060-
f"2FA authentication failed with error code: {resp.status_code}\r\n"
1063+
"2FA authentication failed with error code: %s\r\n",
1064+
resp.status_code,
10611065
)
10621066
return False
10631067

@@ -1099,9 +1103,7 @@ def _getself(self) -> bool:
10991103
print(" Authenticated ".center(80, "-"))
11001104
print(f"\r\nWelcome {self.first_name} {self.last_name}!\r\n")
11011105
LOGGER.info(
1102-
"apisession:_getself:account used: %s %s",
1103-
self.first_name,
1104-
self.last_name,
1106+
"apisession:_getself:account info processed successfully"
11051107
)
11061108
return True
11071109
elif resp.proxy_error:

0 commit comments

Comments
 (0)