Skip to content

Don't print password by default in debug #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions adafruit_esp32spi/adafruit_esp32spi.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def _send_command_get_response(
*,
reply_params=1,
sent_param_len_16=False,
recv_param_len_16=False
recv_param_len_16=False,
):
"""Send a high level SPI command, wait and return the response"""
self._send_command(cmd, params, param_len_16=sent_param_len_16)
Expand Down Expand Up @@ -563,17 +563,23 @@ def connect(self, secrets):
that contains a 'ssid' and 'password' entry"""
self.connect_AP(secrets["ssid"], secrets["password"])

def connect_AP(self, ssid, password, timeout_s=10): # pylint: disable=invalid-name
def connect_AP(
self, ssid, password, timeout_s=10, show_password=False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not have the kwarg here. I think it should go next to the debug flag. It could be debug_show_secrets to cover other sorts of keys in addition to the password.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking! To be clear, you're suggesting it should be an init param?

): # pylint: disable=invalid-name
"""Connect to an access point with given name and password.
Will wait until specified timeout seconds and return on success
or raise an exception on failure.

:param ssid: the SSID to connect to
:param passphrase: the password of the access point
:param timeout_s: number of seconds until we time out and fail to create AP
:param show_password: print password if debug == True (default False)
"""
if self._debug:
print("Connect to AP", ssid, password)
print(
f"Connect to AP: {ssid=}, password=\
{repr(password if show_password else '*' * len(password))}"
)
if isinstance(ssid, str):
ssid = bytes(ssid, "utf-8")
if password:
Expand Down