From ebf535fede8cbcffabc9280bc1fd952954beec81 Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Tue, 2 Jan 2024 14:27:55 -0600 Subject: [PATCH 1/5] Update to SDK v3.34.0 This version of the SDK deprecates `oauth2_validate_token`, so the change replaces it with a direct form-encoded POST in order to maintain the exact same behavior in the CLI for now. --- setup.py | 2 +- src/globus_cli/login_manager/manager.py | 4 +++- tests/functional/test_login_command.py | 10 +++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 6eb22d3b2..dd1a5caef 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ def read_readme(): package_dir={"": "src"}, python_requires=">=3.7", install_requires=[ - "globus-sdk==3.33.0", + "globus-sdk==3.34.0", "click>=8.1.4,<9", "jmespath==1.0.1", "packaging>=17.0", diff --git a/src/globus_cli/login_manager/manager.py b/src/globus_cli/login_manager/manager.py index c17489630..025f766f9 100644 --- a/src/globus_cli/login_manager/manager.py +++ b/src/globus_cli/login_manager/manager.py @@ -87,7 +87,9 @@ def is_logged_in(self) -> bool: def _validate_token(self, token: str) -> bool: auth_client = internal_auth_client() try: - res = auth_client.oauth2_validate_token(token) + res = auth_client.post( + "/v2/oauth2/token/validate", data={"token": token}, encoding="form" + ) # if the instance client is invalid, an AuthAPIError will be raised except globus_sdk.AuthAPIError: return False diff --git a/tests/functional/test_login_command.py b/tests/functional/test_login_command.py index 42f3c5da6..1a3ab86fe 100644 --- a/tests/functional/test_login_command.py +++ b/tests/functional/test_login_command.py @@ -20,7 +20,7 @@ def test_login_validates_token( disable_login_manager_validate_token.undo() with mock.patch("globus_cli.login_manager.manager.internal_auth_client") as m: - ac = mock.MagicMock(spec=globus_sdk.NativeAppAuthClient) + ac = mock.MagicMock(spec=globus_sdk.ConfidentialAppAuthClient) m.return_value = ac run_line("globus login") @@ -28,8 +28,12 @@ def test_login_validates_token( by_rs = mock_login_token_response.by_resource_server a_rt = by_rs["auth.globus.org"]["refresh_token"] t_rt = by_rs["transfer.api.globus.org"]["refresh_token"] - ac.oauth2_validate_token.assert_any_call(a_rt) - ac.oauth2_validate_token.assert_any_call(t_rt) + ac.post.assert_any_call( + "/v2/oauth2/token/validate", data={"token": a_rt}, encoding="form" + ) + ac.post.assert_any_call( + "/v2/oauth2/token/validate", data={"token": t_rt}, encoding="form" + ) class MockToken: From a003a7388ab851c440b8a0b6418ad88b7778145f Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Tue, 2 Jan 2024 14:50:17 -0600 Subject: [PATCH 2/5] Convert from setup.py to setup.cfg All metadata which was dynamically defined in setup.py is now declaratively defined in setup.cfg. --- setup.cfg | 60 ++++++++++++++++++++++++++++++++++++++ setup.py | 87 ++----------------------------------------------------- 2 files changed, 62 insertions(+), 85 deletions(-) diff --git a/setup.cfg b/setup.cfg index 6f7b01c3a..6d1809fe7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,63 @@ +[metadata] +name = globus-cli +version = attr: globus_cli.version.__version__ +description = Globus CLI +long_description = file: README.rst +url = https://github.com/globus/globus-cli +author = Stephen Rosen +author_email = sirosen@globus.org + +keywords = globus, cli, command line +classifiers = + Development Status :: 5 - Production/Stable + Intended Audience :: Developers + License :: OSI Approved :: Apache Software License + Operating System :: POSIX + Programming Language :: Python + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 + +[options] +python_requires = >=3.7 +install_requires = + globus-sdk==3.34.0 + click>=8.1.4,<9 + jmespath==1.0.1 + packaging>=17.0 + typing_extensions>=4.0;python_version<"3.11" + # these are dependencies of the SDK, but they are used directly in the CLI + # declare them here in case the underlying lib ever changes + requests>=2.19.1,<3.0.0 + cryptography>=3.3.1 +package_dir= + =src +packages = find: +include_package_data = true + +[options.packages.find] +where=src + +[options.entry_points] +console_scripts = + globus = globus_cli:main + +[options.extras_require] +test = + coverage>=7 + pytest>=7 + pytest-xdist<3 + pytest-timeout<2 + click-type-test==0.0.5;python_version>='3.10' + responses==0.23.3 + # loading test fixture data + ruamel.yaml==0.17.32 + # Python 3.12 needs setuptools. + setuptools;python_version>='3.12' + [isort] profile = black diff --git a/setup.py b/setup.py index dd1a5caef..606849326 100644 --- a/setup.py +++ b/setup.py @@ -1,86 +1,3 @@ -import os -import re +from setuptools import setup -from setuptools import find_packages, setup - -TEST_REQUIREMENTS = [ - "coverage>=7", - "pytest>=7", - "pytest-xdist<3", - "pytest-timeout<2", - "click-type-test==0.0.5;python_version>='3.10'", - "responses==0.23.3", - # loading test fixture data - "ruamel.yaml==0.17.32", - # Python 3.12 needs setuptools. - "setuptools;python_version>='3.12'", -] -DEV_REQUIREMENTS = TEST_REQUIREMENTS + [ - "tox>=4", - "scriv==1.3.1", -] - - -def parse_version(): - # single source of truth for package version - version_string = "" - version_pattern = re.compile(r'__version__ = "([^"]*)"') - with open(os.path.join("src", "globus_cli", "version.py")) as f: - for line in f: - match = version_pattern.match(line) - if match: - version_string = match.group(1) - break - if not version_string: - raise RuntimeError("Failed to parse version information") - return version_string - - -def read_readme(): - with open("README.rst") as fp: - return fp.read() - - -setup( - name="globus-cli", - version=parse_version(), - packages=find_packages("src"), - package_dir={"": "src"}, - python_requires=">=3.7", - install_requires=[ - "globus-sdk==3.34.0", - "click>=8.1.4,<9", - "jmespath==1.0.1", - "packaging>=17.0", - # these are dependencies of the SDK, but they are used directly in the CLI - # declare them here in case the underlying lib ever changes - "requests>=2.19.1,<3.0.0", - "cryptography>=3.3.1", - # depend on the latest version of typing-extensions on python versions which do - # not have all of the typing features we use - 'typing_extensions>=4.0;python_version<"3.11"', - ], - extras_require={"test": TEST_REQUIREMENTS, "development": DEV_REQUIREMENTS}, - entry_points={"console_scripts": ["globus = globus_cli:main"]}, - # descriptive info, non-critical - description="Globus CLI", - long_description=read_readme(), - long_description_content_type="text/x-rst", - author="Stephen Rosen", - author_email="sirosen@globus.org", - url="https://github.com/globus/globus-cli", - keywords=["globus", "cli", "command line"], - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", - "Operating System :: POSIX", - "Programming Language :: Python", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - ], -) +setup() From 5116a1ffab8503b44a73be548327b435d75c0393 Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Tue, 2 Jan 2024 14:56:49 -0600 Subject: [PATCH 3/5] Convert to pyproject.toml Convert setup.cfg to pyproject.toml + .flake8 --- .flake8 | 9 ++++++ pyproject.toml | 80 +++++++++++++++++++++++++++++++++++++++++++++ setup.cfg | 88 -------------------------------------------------- 3 files changed, 89 insertions(+), 88 deletions(-) create mode 100644 .flake8 create mode 100644 pyproject.toml delete mode 100644 setup.cfg diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..1e845d85a --- /dev/null +++ b/.flake8 @@ -0,0 +1,9 @@ +[flake8] # black and isort compatible rules +exclude = .git,.tox,__pycache__,.eggs,dist,venv,.venv*,venv27,virtualenv,adoc,build +max-line-length = 88 +ignore = W503,W504,E203 + +[flake8:local-plugins] +extension = + CLI = globus_cli_flake8:Plugin +paths = ./src/globus_cli/ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..36582c6e3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,80 @@ +[build-system] +requires = ["setuptools>=61.2"] +build-backend = "setuptools.build_meta" + +[project] +name = "globus-cli" +description = "Globus CLI" +readme = "README.rst" +authors = [ + { name = "Stephen Rosen", email = "sirosen@globus.org" }, +] +keywords = [ + "globus", + "cli", + "command line", +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Operating System :: POSIX", + "Programming Language :: Python", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", +] +requires-python = ">=3.7" +dependencies = [ + "globus-sdk==3.34.0", + "click>=8.1.4,<9", + "jmespath==1.0.1", + "packaging>=17.0", + "typing_extensions>=4.0;python_version<\"3.11\"", + # these are dependencies of the SDK, but they are used directly in the CLI + # declare them here in case the underlying lib ever changes + "requests>=2.19.1,<3.0.0", + "cryptography>=3.3.1", +] +dynamic = ["version"] + +[project.urls] +homepage = "https://github.com/globus/globus-cli" + +[project.optional-dependencies] +test = [ + "coverage>=7", + "pytest>=7", + "pytest-xdist<3", + "pytest-timeout<2", + "click-type-test==0.0.5;python_version>='3.10'", + "responses==0.23.3", + # loading test fixture data + "ruamel.yaml==0.17.32", + # Python 3.12 needs setuptools. + "setuptools;python_version>='3.12'", +] + +[project.scripts] +globus = "globus_cli:main" + +[tool.setuptools.dynamic.version] +attr = "globus_cli.version.__version__" + +[tool.isort] +profile = "black" + +[tool.pytest.ini_options] +addopts = "--timeout 3" +filterwarnings = ["error"] + +[tool.scriv] +version = "literal: src/globus_cli/version.py: __version__" +categories = "Bugfixes, Enhancements, Other" +# we're using adoc, we'll produce fragments as 'md' and "fix" later +format = "md" +output_file = "changelog.adoc" +entry_title_template = '{{ version }} ({{ date.strftime("%Y-%m-%d") }})' diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 6d1809fe7..000000000 --- a/setup.cfg +++ /dev/null @@ -1,88 +0,0 @@ -[metadata] -name = globus-cli -version = attr: globus_cli.version.__version__ -description = Globus CLI -long_description = file: README.rst -url = https://github.com/globus/globus-cli -author = Stephen Rosen -author_email = sirosen@globus.org - -keywords = globus, cli, command line -classifiers = - Development Status :: 5 - Production/Stable - Intended Audience :: Developers - License :: OSI Approved :: Apache Software License - Operating System :: POSIX - Programming Language :: Python - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Programming Language :: Python :: 3.11 - Programming Language :: Python :: 3.12 - -[options] -python_requires = >=3.7 -install_requires = - globus-sdk==3.34.0 - click>=8.1.4,<9 - jmespath==1.0.1 - packaging>=17.0 - typing_extensions>=4.0;python_version<"3.11" - # these are dependencies of the SDK, but they are used directly in the CLI - # declare them here in case the underlying lib ever changes - requests>=2.19.1,<3.0.0 - cryptography>=3.3.1 -package_dir= - =src -packages = find: -include_package_data = true - -[options.packages.find] -where=src - -[options.entry_points] -console_scripts = - globus = globus_cli:main - -[options.extras_require] -test = - coverage>=7 - pytest>=7 - pytest-xdist<3 - pytest-timeout<2 - click-type-test==0.0.5;python_version>='3.10' - responses==0.23.3 - # loading test fixture data - ruamel.yaml==0.17.32 - # Python 3.12 needs setuptools. - setuptools;python_version>='3.12' - -[isort] -profile = black - - -[flake8] # black and isort compatible rules -exclude = .git,.tox,__pycache__,.eggs,dist,venv,.venv*,venv27,virtualenv,adoc,build -max-line-length = 88 -ignore = W503,W504,E203 - -[flake8:local-plugins] -extension = - CLI = globus_cli_flake8:Plugin -paths = ./src/globus_cli/ - - -[tool:pytest] -addopts = --timeout 3 -filterwarnings = - # warnings are errors, like -Werror - error - -[scriv] -version = literal: src/globus_cli/version.py: __version__ -categories = Bugfixes, Enhancements, Other -# we're using adoc, we'll produce fragments as 'md' and "fix" later -format = md -output_file = changelog.adoc -entry_title_template = {{ version }} ({{ date.strftime("%%Y-%%m-%%d") }}) From 052bc521fbb26c307eea72e217ff885f3bbaccc0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 Jan 2024 21:17:33 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/globus_cli/commands/endpoint/permission/update.py | 2 +- src/globus_cli/commands/endpoint/show.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/globus_cli/commands/endpoint/permission/update.py b/src/globus_cli/commands/endpoint/permission/update.py index 3624bdbf1..7070eab1f 100644 --- a/src/globus_cli/commands/endpoint/permission/update.py +++ b/src/globus_cli/commands/endpoint/permission/update.py @@ -40,7 +40,7 @@ def update_command( *, permissions: Literal["r", "rw"], rule_id: str, - endpoint_id: uuid.UUID + endpoint_id: uuid.UUID, ) -> None: """ Update an existing access control rule's permissions. diff --git a/src/globus_cli/commands/endpoint/show.py b/src/globus_cli/commands/endpoint/show.py index 109a04b05..443007ba9 100644 --- a/src/globus_cli/commands/endpoint/show.py +++ b/src/globus_cli/commands/endpoint/show.py @@ -44,7 +44,7 @@ def endpoint_show( login_manager: LoginManager, *, endpoint_id: uuid.UUID, - skip_endpoint_type_check: bool + skip_endpoint_type_check: bool, ) -> None: """Display a detailed endpoint definition""" transfer_client = login_manager.get_transfer_client() From 33f8807cc50ec8dd5c2669602b52f1611ef1897b Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Wed, 3 Jan 2024 16:29:34 -0600 Subject: [PATCH 5/5] Minor quoting consistency fix --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 36582c6e3..4c1e4b1e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ dependencies = [ "click>=8.1.4,<9", "jmespath==1.0.1", "packaging>=17.0", - "typing_extensions>=4.0;python_version<\"3.11\"", + "typing_extensions>=4.0;python_version<'3.11'", # these are dependencies of the SDK, but they are used directly in the CLI # declare them here in case the underlying lib ever changes "requests>=2.19.1,<3.0.0",