diff --git a/gsutil.py b/gsutil.py index 4dcb2d6177..3534760683 100755 --- a/gsutil.py +++ b/gsutil.py @@ -36,6 +36,10 @@ LUCI_AUTH_SCOPES = [ ] +# Platforms unsupported by luci-auth. +LUCI_AUTH_UNSUPPORTED_PLATFORMS = ['aix'] + + class InvalidGsutilError(Exception): pass @@ -154,6 +158,12 @@ def _is_luci_context(): return False +def _is_luci_auth_supported_platform(): + """Returns True if luci-auth is supported in the current platform.""" + return not any(map(sys.platform.startswith, + LUCI_AUTH_UNSUPPORTED_PLATFORMS)) + + def luci_context(cmd): """Helper to call`luci-auth context`.""" p = _luci_auth_cmd('context', wrapped_cmds=cmd) @@ -264,8 +274,9 @@ def run_gsutil(target, args, clean=False): _print_subprocess_result(p) return p.returncode - # Skip wrapping commands if luci-auth is already being - if _is_luci_context(): + # Skip wrapping commands if luci-auth is already being used or if the + # platform is unsupported by luci-auth. + if _is_luci_context() or not _is_luci_auth_supported_platform(): return _run_subprocess(cmd, interactive=True).returncode # Wrap gsutil with luci-auth context. diff --git a/tests/gsutil_test.py b/tests/gsutil_test.py index 39e09187ed..1c79bb8eec 100755 --- a/tests/gsutil_test.py +++ b/tests/gsutil_test.py @@ -16,6 +16,7 @@ import tempfile import unittest import zipfile import urllib.request +from unittest import mock # Add depot_tools to path THIS_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -147,5 +148,15 @@ class GsutilUnitTests(unittest.TestCase): gsutil_bin) + @mock.patch('sys.platform', 'linux') + def test__is_supported_platform_returns_true_for_supported_platform(self): + self.assertTrue(gsutil._is_luci_auth_supported_platform()) + + @mock.patch('sys.platform', 'aix') + def test__is_supported_platform_returns_false_for_unsupported_platform( + self): + self.assertFalse(gsutil._is_luci_auth_supported_platform()) + + if __name__ == '__main__': unittest.main()