mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
[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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user