[git_cl] Parametrize email in ShouldUseSSO

Moves the dependency on Git+cwd up the call stack

Bug: b/351071334
Change-Id: Ia313f9d4720ee10398b757217c333118e9fc7341
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5723091
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
This commit is contained in:
Allen Li
2024-07-20 00:48:36 +00:00
committed by LUCI CQ
parent e7cc4c93c0
commit 91937bf196
3 changed files with 20 additions and 20 deletions

View File

@@ -171,8 +171,8 @@ class SSOHelper(object):
ssoHelper = SSOHelper()
def ShouldUseSSO(cwd: str, host: str) -> bool:
"""Return True if we should use SSO for the current user."""
def ShouldUseSSO(host: str, email: str) -> bool:
"""Return True if we should use SSO for the given Gerrit host and user."""
LOGGER.debug("Determining whether we should use SSO...")
if not newauth.Enabled():
LOGGER.debug("SSO=False: not opted in")
@@ -183,7 +183,6 @@ def ShouldUseSSO(cwd: str, host: str) -> bool:
if not ssoHelper.find_cmd():
LOGGER.debug("SSO=False: no SSO command")
return False
email = scm.GIT.GetConfig(cwd, 'user.email', default='')
if email.endswith('@google.com'):
LOGGER.debug("SSO=True: email is google.com")
return True
@@ -363,9 +362,9 @@ class SSOAuthenticator(_Authenticator):
def is_applicable(cls, *, conn: Optional[HttpConn] = None) -> bool:
if not cls._resolve_sso_cmd():
return False
email: str = scm.GIT.GetConfig(os.getcwd(), 'user.email', default='')
if conn is not None:
return ShouldUseSSO(os.getcwd(), conn.host)
email = scm.GIT.GetConfig(os.getcwd(), 'user.email', default='')
return ShouldUseSSO(conn.host, email)
return email.endswith('@google.com')
@classmethod