Skip to content

Commit

Permalink
Improved password prompting in interactive mode
Browse files Browse the repository at this point in the history
* Improved password prompting in interactive mode so that there is now only a
  single password prompt when no password is specified.
  Previously, each interactive command prompted for the password in that case.

Signed-off-by: Andreas Maier <[email protected]>
  • Loading branch information
andy-maier committed Jan 8, 2025
1 parent b70aed0 commit e387d99
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changes/688.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Improved password prompting in interactive mode so that there is now only a
single password prompt when no password is specified.
Previously, each interactive command prompted for the password in that case.
21 changes: 17 additions & 4 deletions zhmccli/zhmccli.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,7 @@ def get_password_via_prompt(host, userid):
"""
if userid is not None and host is not None:
ctx.obj.spinner.stop()
password = click.prompt(
"Enter password (for user {userid} at HMC {host})".
format(userid=userid, host=host), hide_input=True,
confirmation_prompt=False, type=str, err=True)
password = get_password(host, userid)
ctx.obj.spinner.start()
return password

Expand All @@ -338,6 +335,11 @@ def get_password_via_prompt(host, userid):
format(cmd=ctx.invoked_subcommand),
error_format)

# Make sure that in interactive mode, we have the password (otherwise,
# every interactive command prompts for it).
if password is None and ctx.invoked_subcommand in (None, 'repl'):
password = get_password(host, userid)

# We create a command context for each command: An interactive command has
# its own command context different from the command context for the
# command line.
Expand All @@ -350,6 +352,17 @@ def get_password_via_prompt(host, userid):
ctx.invoke(repl)


def get_password(host, userid):
"""
Prompt for a password and return the password.
"""
password = click.prompt(
"Enter password (for user {userid} at HMC {host})".
format(userid=userid, host=host), hide_input=True,
confirmation_prompt=False, type=str, err=True)
return password


def reset_logger(log_comp):
"""
Reset the logger for the specified log component to have exactly one
Expand Down

0 comments on commit e387d99

Please sign in to comment.