瀏覽代碼

[git_auth] Rename GitAuthMode

Bug: b/351071334
Change-Id: I29bfdff79e04d2df3df62019fc0c7dfd87dd302f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5739675
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
Allen Li 1 年之前
父節點
當前提交
fed7aa526c
共有 2 個文件被更改,包括 24 次插入24 次删除
  1. 22 22
      git_auth.py
  2. 2 2
      git_cl.py

+ 22 - 22
git_auth.py

@@ -13,7 +13,7 @@ import urllib.parse
 import scm
 
 
-class GitAuthMode(enum.Enum):
+class ConfigMode(enum.Enum):
     """Modes to pass to GitAuthConfigChanger"""
     NO_AUTH = 1
     NEW_AUTH = 2
@@ -33,7 +33,7 @@ class GitAuthConfigChanger(object):
     def __init__(
         self,
         *,
-        mode: GitAuthMode,
+        mode: ConfigMode,
         remote_url: str,
         set_config_func: Callable[..., None] = scm.GIT.SetConfig,
     ):
@@ -46,7 +46,7 @@ class GitAuthConfigChanger(object):
             set_config_func: Function used to set configuration.  Used
                 for testing.
         """
-        self.mode: GitAuthMode = mode
+        self.mode: ConfigMode = mode
 
         self._remote_url: str = remote_url
         self._set_config_func: Callable[..., str] = set_config_func
@@ -93,14 +93,14 @@ class GitAuthConfigChanger(object):
         )
 
     @staticmethod
-    def _infer_mode(cwd: str, gerrit_host: str) -> GitAuthMode:
+    def _infer_mode(cwd: str, gerrit_host: str) -> ConfigMode:
         """Infer default mode to use."""
         if not newauth.Enabled():
-            return GitAuthMode.NO_AUTH
+            return ConfigMode.NO_AUTH
         email: str = scm.GIT.GetConfig(cwd, 'user.email', default='')
         if gerrit_util.ShouldUseSSO(gerrit_host, email):
-            return GitAuthMode.NEW_AUTH_SSO
-        return GitAuthMode.NEW_AUTH
+            return ConfigMode.NEW_AUTH_SSO
+        return ConfigMode.NEW_AUTH
 
     def apply(self, cwd: str) -> None:
         """Apply config changes to the Git repo directory."""
@@ -120,12 +120,12 @@ class GitAuthConfigChanger(object):
     def _apply_cred_helper(self, cwd: str) -> None:
         """Apply config changes relating to credential helper."""
         cred_key: str = f'credential.{self._base_url}.helper'
-        if self.mode == GitAuthMode.NEW_AUTH:
+        if self.mode == ConfigMode.NEW_AUTH:
             self._set_config(cwd, cred_key, '', modify_all=True)
             self._set_config(cwd, cred_key, 'luci', append=True)
-        elif self.mode == GitAuthMode.NEW_AUTH_SSO:
+        elif self.mode == ConfigMode.NEW_AUTH_SSO:
             self._set_config(cwd, cred_key, None, modify_all=True)
-        elif self.mode == GitAuthMode.NO_AUTH:
+        elif self.mode == ConfigMode.NO_AUTH:
             self._set_config(cwd, cred_key, None, modify_all=True)
         else:
             raise TypeError(f'Invalid mode {self.mode!r}')
@@ -133,13 +133,13 @@ class GitAuthConfigChanger(object):
     def _apply_sso(self, cwd: str) -> None:
         """Apply config changes relating to SSO."""
         sso_key: str = f'url.sso://{self._shortname}/.insteadOf'
-        if self.mode == GitAuthMode.NEW_AUTH:
+        if self.mode == ConfigMode.NEW_AUTH:
             self._set_config(cwd, 'protocol.sso.allow', None)
             self._set_config(cwd, sso_key, None, modify_all=True)
-        elif self.mode == GitAuthMode.NEW_AUTH_SSO:
+        elif self.mode == ConfigMode.NEW_AUTH_SSO:
             self._set_config(cwd, 'protocol.sso.allow', 'always')
             self._set_config(cwd, sso_key, self._base_url, modify_all=True)
-        elif self.mode == GitAuthMode.NO_AUTH:
+        elif self.mode == ConfigMode.NO_AUTH:
             self._set_config(cwd, 'protocol.sso.allow', None)
             self._set_config(cwd, sso_key, None, modify_all=True)
         else:
@@ -149,13 +149,13 @@ class GitAuthConfigChanger(object):
         """Apply config changes relating to gitcookies."""
         # TODO(ayatane): Clear invalid setting.  Remove line after a few weeks
         self._set_config(cwd, 'http.gitcookies', None, modify_all=True)
-        if self.mode == GitAuthMode.NEW_AUTH:
+        if self.mode == ConfigMode.NEW_AUTH:
             # Override potential global setting
             self._set_config(cwd, 'http.cookieFile', '', modify_all=True)
-        elif self.mode == GitAuthMode.NEW_AUTH_SSO:
+        elif self.mode == ConfigMode.NEW_AUTH_SSO:
             # Override potential global setting
             self._set_config(cwd, 'http.cookieFile', '', modify_all=True)
-        elif self.mode == GitAuthMode.NO_AUTH:
+        elif self.mode == ConfigMode.NO_AUTH:
             self._set_config(cwd, 'http.cookieFile', None, modify_all=True)
         else:
             raise TypeError(f'Invalid mode {self.mode!r}')
@@ -163,14 +163,14 @@ class GitAuthConfigChanger(object):
     def _apply_global_cred_helper(self, cwd: str) -> None:
         """Apply config changes relating to credential helper."""
         cred_key: str = f'credential.{self._base_url}.helper'
-        if self.mode == GitAuthMode.NEW_AUTH:
+        if self.mode == ConfigMode.NEW_AUTH:
             self._set_config(cwd, cred_key, '', scope='global', modify_all=True)
             self._set_config(cwd, cred_key, 'luci', scope='global', append=True)
-        elif self.mode == GitAuthMode.NEW_AUTH_SSO:
+        elif self.mode == ConfigMode.NEW_AUTH_SSO:
             # Avoid editing the user's config in case they manually
             # configured something.
             pass
-        elif self.mode == GitAuthMode.NO_AUTH:
+        elif self.mode == ConfigMode.NO_AUTH:
             # Avoid editing the user's config in case they manually
             # configured something.
             pass
@@ -180,7 +180,7 @@ class GitAuthConfigChanger(object):
     def _apply_global_sso(self, cwd: str) -> None:
         """Apply config changes relating to SSO."""
         sso_key: str = f'url.sso://{self._shortname}/.insteadOf'
-        if self.mode == GitAuthMode.NEW_AUTH:
+        if self.mode == ConfigMode.NEW_AUTH:
             # Do not unset protocol.sso.allow because it may be used by
             # other hosts.
             self._set_config(cwd,
@@ -188,7 +188,7 @@ class GitAuthConfigChanger(object):
                              None,
                              scope='global',
                              modify_all=True)
-        elif self.mode == GitAuthMode.NEW_AUTH_SSO:
+        elif self.mode == ConfigMode.NEW_AUTH_SSO:
             self._set_config(cwd,
                              'protocol.sso.allow',
                              'always',
@@ -198,7 +198,7 @@ class GitAuthConfigChanger(object):
                              self._base_url,
                              scope='global',
                              modify_all=True)
-        elif self.mode == GitAuthMode.NO_AUTH:
+        elif self.mode == ConfigMode.NO_AUTH:
             # Avoid editing the user's config in case they manually
             # configured something.
             pass

+ 2 - 2
git_cl.py

@@ -3683,7 +3683,7 @@ def ConfigureGitAuth() -> None:
         logging.debug(
             'Local user wants same mode %s as global; clearing local repo auth config',
             c2.mode)
-        c2.mode = git_auth.GitAuthMode.NO_AUTH
+        c2.mode = git_auth.ConfigMode.NO_AUTH
         c2.apply(cwd)
         return
     logging.debug('Local user wants mode %s while global user wants mode %s',
@@ -3704,7 +3704,7 @@ def ClearGitRepoAuth() -> None:
     """Clear the current Git repo authentication."""
     logging.debug('Clearing current Git repo authentication...')
     c = git_auth.GitAuthConfigChanger.new_from_env(cwd)
-    c.mode = git_auth.GitAuthMode.NO_AUTH
+    c.mode = git_auth.ConfigMode.NO_AUTH
     c.apply(cwd)