Skip to content

Commit

Permalink
Change the order for password prompt and keychain.
Browse files Browse the repository at this point in the history
  • Loading branch information
amjith committed Jan 13, 2022
1 parent 6d719b6 commit 338ea21
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pgcli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,17 @@ def connect(
- uninstall keyring: pip uninstall keyring
- disable keyring in our configuration: add keyring = False to [main]"""
)

# Prompt for a password immediately if requested via the -W flag. This
# avoids wasting time trying to connect to the database and catching a
# no-password exception.
# If we successfully parsed a password from a URI, there's no need to
# prompt for it, even with the -W flag
if self.force_passwd_prompt and not passwd:
passwd = click.prompt(
"Password for %s" % user, hide_input=True, show_default=False, type=str
)

if not passwd and keyring:

try:
Expand All @@ -562,16 +573,6 @@ def connect(
fg="red",
)

# Prompt for a password immediately if requested via the -W flag. This
# avoids wasting time trying to connect to the database and catching a
# no-password exception.
# If we successfully parsed a password from a URI, there's no need to
# prompt for it, even with the -W flag
if self.force_passwd_prompt and not passwd:
passwd = click.prompt(
"Password for %s" % user, hide_input=True, show_default=False, type=str
)

def should_ask_for_password(exc):
# Prompt for a password after 1st attempt to connect
# fails. Don't prompt if the -w flag is supplied
Expand Down

0 comments on commit 338ea21

Please sign in to comment.