Skip to content

Commit 500479e

Browse files
committed
cli: If 'login' called but we have an API key, print and exit
Otherwise the API throws an unfriendly error Signed-off-by: Cole Robinson <[email protected]>
1 parent 4215086 commit 500479e

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

bugzilla/_cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,10 @@ def _handle_login(opt, action, bz):
10401040
if use_key:
10411041
bz.interactive_save_api_key()
10421042
elif do_interactive_login:
1043+
if bz.api_key:
1044+
print("You already have an API key configured for %s" % bz.url)
1045+
print("There is no need to cache a login token. Exiting.")
1046+
sys.exit(0)
10431047
print("Logging into %s" % urlparse(bz.url)[1])
10441048
bz.interactive_login(username, password,
10451049
restrict_login=opt.restrict_login)

tests/test_cli_login.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,9 @@ def test_interactive_login(monkeypatch, run_cli):
100100
assert tmp.name in out
101101
tests.utils.diff_compare(open(tmp.name).read(),
102102
"data/clioutput/test_interactive_login_apikey_rcfile.txt")
103+
104+
# Check that we don't attempt to log in if API key is configured
105+
assert bz.api_key
106+
cmd = "bugzilla login"
107+
out = run_cli(cmd, bz)
108+
assert "already have an API" in out

0 commit comments

Comments
 (0)