فهرست منبع

[gerrit_util] Add newauth.py helper

These checks will be needed in git_cl.py and probably other places.

Make it easy to change the default to opt-in as some point (and for
deletion later).

Bug: b/348024314
Change-Id: I768986e47ec2e86604268d74ca2b632458263bba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5641084
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Allen Li 1 سال پیش
والد
کامیت
fa1bba51d7
2فایلهای تغییر یافته به همراه23 افزوده شده و 4 حذف شده
  1. 3 4
      gerrit_util.py
  2. 20 0
      newauth.py

+ 3 - 4
gerrit_util.py

@@ -40,6 +40,7 @@ import auth
 import gclient_utils
 import gclient_utils
 import metrics
 import metrics
 import metrics_utils
 import metrics_utils
+import newauth
 import scm
 import scm
 import subprocess2
 import subprocess2
 
 
@@ -177,12 +178,10 @@ class Authenticator(object):
         Probes the local system and its environment and identifies the
         Probes the local system and its environment and identifies the
         Authenticator instance to use.
         Authenticator instance to use.
         """
         """
-        use_new_auth = scm.GIT.GetConfig(os.getcwd(),
-                                         'depot-tools.usenewauthstack') == '1'
+        use_new_auth = newauth.Enabled()
 
 
         # Allow skipping SSOAuthenticator for local testing purposes.
         # Allow skipping SSOAuthenticator for local testing purposes.
-        skip_sso = scm.GIT.GetConfig(os.getcwd(),
-                                     'depot-tools.newauthskipsso') == '1'
+        skip_sso = newauth.SkipSSO()
 
 
         authenticators: List[Type[Authenticator]]
         authenticators: List[Type[Authenticator]]
 
 

+ 20 - 0
newauth.py

@@ -0,0 +1,20 @@
+# Copyright (c) 2024 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""Defines common conditions for the new auth stack migration."""
+
+from __future__ import annotations
+
+import os
+
+import scm
+
+
+def Enabled() -> bool:
+    """Returns True if new auth stack is enabled."""
+    return scm.GIT.GetConfig(os.getcwd(), 'depot-tools.usenewauthstack') == '1'
+
+
+def SkipSSO() -> bool:
+    """Returns True if skip SSO is set."""
+    return scm.GIT.GetConfig(os.getcwd(), 'depot-tools.newauthskipsso') == '1'