浏览代码

[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>
Allen Li 1 年之前
父节点
当前提交
6359e82d13
共有 1 个文件被更改,包括 38 次插入8 次删除
  1. 38 8
      git_cl.py

+ 38 - 8
git_cl.py

@@ -51,6 +51,7 @@ import git_new_branch
 import google_java_format
 import google_java_format
 import metrics
 import metrics
 import metrics_utils
 import metrics_utils
+import newauth
 import owners_client
 import owners_client
 import owners_finder
 import owners_finder
 import presubmit_canned_checks
 import presubmit_canned_checks
@@ -3610,6 +3611,32 @@ def DownloadGerritHook(force):
                          'chmod +x .git/hooks/commit-msg' % src)
                          '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):
 class _GitCookiesChecker(object):
     """Provides facilities for validating and suggesting fixes to .gitcookies."""
     """Provides facilities for validating and suggesting fixes to .gitcookies."""
     def __init__(self):
     def __init__(self):
@@ -3843,16 +3870,19 @@ def CMDcreds_check(parser, args):
                 'export SKIP_GCE_AUTH_FOR_GIT=1 in your env.')
                 'export SKIP_GCE_AUTH_FOR_GIT=1 in your env.')
         DieWithError(message)
         DieWithError(message)
 
 
-    checker = _GitCookiesChecker()
-    checker.ensure_configured_gitcookies()
+    if newauth.Enabled():
+        ConfigureGitRepoAuth()
+    else:
+        checker = _GitCookiesChecker()
+        checker.ensure_configured_gitcookies()
 
 
-    print('Your .gitcookies have credentials for these hosts:')
-    checker.print_current_creds()
+        print('Your .gitcookies have credentials for these hosts:')
+        checker.print_current_creds()
 
 
-    if not checker.find_and_report_problems():
-        print('\nNo problems detected in your .gitcookies file.')
-        return 0
-    return 1
+        if not checker.find_and_report_problems():
+            print('\nNo problems detected in your .gitcookies file.')
+            return 0
+        return 1
 
 
 
 
 @metrics.collector.collect_metrics('git cl baseurl')
 @metrics.collector.collect_metrics('git cl baseurl')