git-cl: fix gerrit_host and git_host ordering in ensure_authenticated

ensure_authenticated was defined to take gerrit_host then git_host,
but the callsite got it flipped in https://crrev.com/c/5665455

This CL fixes the mistake, and also changed the method signature to
require kwargs argument (and hopefully make it easier to spot and avoid
such mistakes).

Note, this change shouldn't impact normal operation. Only the deprecated
CookiesAuthenticator relies on git_host and gerrit_host, which is not
used when New Auth Stack is enabled.

Bug: 451651615
Change-Id: I8157f3bd4cd51cc78dc4e1c2a917682ced91da86
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7077739
Auto-Submit: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Scott Lee <ddoman@chromium.org>
This commit is contained in:
Jiewei Qian
2025-10-23 10:07:32 -07:00
committed by LUCI CQ
parent 2b9b70b8b9
commit cd260a79de
2 changed files with 9 additions and 5 deletions

View File

@@ -273,7 +273,8 @@ class _Authenticator(object):
"""
raise NotImplementedError()
def ensure_authenticated(self, gerrit_host: str, git_host: str) -> Tuple[bool, str]:
def ensure_authenticated(self, *, gerrit_host: str,
git_host: str) -> Tuple[bool, str]:
"""Returns (bypassable, error message).
If the error message is empty, there is no error to report.
@@ -343,13 +344,15 @@ def debug_auth() -> Tuple[str, str]:
return authn.__class__.__name__, authn.debug_summary_state()
def ensure_authenticated(gerrit_host: str, git_host: str) -> Tuple[bool, str]:
def ensure_authenticated(*, gerrit_host: str,
git_host: str) -> Tuple[bool, str]:
"""Returns (bypassable, error message).
If the error message is empty, there is no error to report. If bypassable is
true, the caller will allow the user to continue past the error.
"""
return _Authenticator.get().ensure_authenticated(gerrit_host, git_host)
return _Authenticator.get().ensure_authenticated(gerrit_host=gerrit_host,
git_host=git_host)
class SSOAuthenticator(_Authenticator):
@@ -702,7 +705,8 @@ class CookiesAuthenticator(_Authenticator):
else:
conn.req_headers['Authorization'] = f'Bearer {cred}'
def ensure_authenticated(self, gerrit_host: str, git_host: str) -> Tuple[bool, str]:
def ensure_authenticated(self, *, gerrit_host: str,
git_host: str) -> Tuple[bool, str]:
"""Returns (bypassable, error message).
If the error message is empty, there is no error to report.