[git_cl] Add new auth support for creds check

Bug: b/348024314
Change-Id: I157380b19121a9fbcee2a1a13447df9c03f7bccc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5646659
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
changes/59/5646659/4
Allen Li 10 months ago committed by LUCI CQ
parent bb38aa2f8e
commit 6359e82d13

@ -51,6 +51,7 @@ import git_new_branch
import google_java_format
import metrics
import metrics_utils
import newauth
import owners_client
import owners_finder
import presubmit_canned_checks
@ -3610,6 +3611,32 @@ def DownloadGerritHook(force):
'chmod +x .git/hooks/commit-msg' % src)
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:
scm.GIT.SetConfig(cwd,
f'credential.{gerrit_host}.helper',
None,
modify_all=True)
else:
scm.GIT.SetConfig(cwd,
f'credential.{gerrit_host}.helper',
'',
modify_all=True)
scm.GIT.SetConfig(cwd, f'credential.{gerrit_host}.helper', 'luci')
# Override potential global gitcookie config
scm.GIT.SetConfig(cwd, 'http.gitcookies', '', modify_all=True)
class _GitCookiesChecker(object):
"""Provides facilities for validating and suggesting fixes to .gitcookies."""
def __init__(self):
@ -3843,6 +3870,9 @@ def CMDcreds_check(parser, args):
'export SKIP_GCE_AUTH_FOR_GIT=1 in your env.')
DieWithError(message)
if newauth.Enabled():
ConfigureGitRepoAuth()
else:
checker = _GitCookiesChecker()
checker.ensure_configured_gitcookies()

Loading…
Cancel
Save