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'