From fa1bba51d7e413bb03c6dd1f5b5c278ce50b20d8 Mon Sep 17 00:00:00 2001 From: Allen Li Date: Thu, 20 Jun 2024 21:51:48 +0000 Subject: [PATCH] [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 Reviewed-by: Gavin Mak --- gerrit_util.py | 7 +++---- newauth.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 newauth.py diff --git a/gerrit_util.py b/gerrit_util.py index 9dad25cbf..579dea76b 100644 --- a/gerrit_util.py +++ b/gerrit_util.py @@ -40,6 +40,7 @@ import auth import gclient_utils import metrics import metrics_utils +import newauth import scm import subprocess2 @@ -177,12 +178,10 @@ class Authenticator(object): Probes the local system and its environment and identifies the 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. - skip_sso = scm.GIT.GetConfig(os.getcwd(), - 'depot-tools.newauthskipsso') == '1' + skip_sso = newauth.SkipSSO() authenticators: List[Type[Authenticator]] diff --git a/newauth.py b/newauth.py new file mode 100644 index 000000000..10540be6b --- /dev/null +++ b/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'