[gerrit_util] Add ShouldUseSSO helper

Bug: b/348024314
Change-Id: I5b061bc6afeffbc84aee12250732e96a0ad0f32b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5651287
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
changes/87/5651287/3
Allen Li 1 year ago committed by LUCI CQ
parent 8ac3425344
commit 3a5d348a0b

@ -171,6 +171,18 @@ class SSOHelper(object):
ssoHelper = SSOHelper()
def ShouldUseSSO() -> bool:
"""Return True if we should use SSO for the current user."""
if not newauth.Enabled():
return False
if not ssoHelper.find_cmd():
return False
cwd = os.getcwd()
email = scm.GIT.GetConfig(cwd, 'user.email', default='')
# TODO(ayatane): enable logic not finished, for linked accounts
return email.endswith('@google.com')
class Authenticator(object):
"""Base authenticator class for authenticator implementations to subclass."""

@ -3614,14 +3614,9 @@ def DownloadGerritHook(force):
def ConfigureGitRepoAuth() -> None:
"""Configure the current Git repo authentication."""
cl = Changelist()
gerrit_host = cl.GetGerritHost()
cwd = os.getcwd()
email = scm.GIT.GetConfig(cwd, 'user.email', default='')
# TODO(ayatane): enable logic not finished, for linked accounts
enable_sso = gerrit_util.ssoHelper.find_cmd() and email.endswith(
'@google.com')
if enable_sso:
gerrit_host = cl.GetGerritHost()
if gerrit_util.ShouldUseSSO(email):
scm.GIT.SetConfig(cwd,
f'credential.{gerrit_host}.helper',
None,

Loading…
Cancel
Save