💫 Toolkit to help you get started with SDD or any other process!
chore: organize authentication domain (#4678)
Manfred Rieme1046bd55704
diff --git a/src/specify_cli/_github_http.py b/src/specify_cli/authentication/github_http.pysimilarity index 98%rename from src/specify_cli/_github_http.pyrename to src/specify_cli/authentication/github_http.pyindex 0b6b9be18..402a147d6 100644--- a/src/specify_cli/_github_http.py+++ b/src/specify_cli/authentication/github_http.py@@ -1,4 +1,4 @@-"""Shared GitHub HTTP request helpers.+"""GitHub-specific HTTP request helpers for the authentication domain.Provides ``build_github_request()`` for attaching GITHUB_TOKEN / GH_TOKENcredentials to requests targeting GitHub-hosted domains, and@@ -107,7 +107,7 @@ def resolve_github_release_asset_api_url(Args:download_url: The URL to resolve.open_url_fn: A callable compatible with- ``specify_cli.authentication.http.open_url`` used for the+ :func:`specify_cli.authentication.http.open_url` used for theauthenticated release-metadata lookup.timeout: Per-request timeout in seconds.github_hosts: Host patterns to treat as GitHub Enterprise Server.@@ -117,7 +117,7 @@ def resolve_github_release_asset_api_url(import jsonimport urllib.error- from specify_cli._download_security import read_response_limited+ from .._download_security import read_response_limited# Accessing ``.hostname`` (like ``.port`` below) raises ValueError on a# malformed authority, e.g. an invalid bracketed IPv6 hostdiff --git a/src/specify_cli/bundles/sources.py b/src/specify_cli/bundles/sources.pyindex 3d78d2973..581969c66 100644--- a/src/specify_cli/bundles/sources.py+++ b/src/specify_cli/bundles/sources.py@@ -190,7 +190,7 @@ def _download_remote_manifest(import yaml as _yamlfrom ..authentication.http import github_provider_hosts, open_url- from .._github_http import resolve_github_release_asset_api_url+ from ..authentication.github_http import resolve_github_release_asset_api_urlfrom .manifest import BundleManifestfrom ..shared_infra import verify_archive_sha256diff --git a/src/specify_cli/extensions/__init__.py b/src/specify_cli/extensions/__init__.pyindex 775ade731..e4b9e7de9 100644--- a/src/specify_cli/extensions/__init__.py+++ b/src/specify_cli/extensions/__init__.py@@ -3793,11 +3793,12 @@ class ExtensionCatalog(CatalogStackBase):) -> Optional[str]:"""Resolve a GitHub release asset URL to its API asset URL.- Delegates to the shared helper in :mod:`specify_cli._github_http`,+ Delegates to the shared helper in+ :mod:`specify_cli.authentication.github_http`,passing the ``github`` provider hosts from ``auth.json`` so GitHubEnterprise Server release assets resolve via ``/api/v3``."""- from specify_cli._github_http import resolve_github_release_asset_api_url+ from specify_cli.authentication.github_http import resolve_github_release_asset_api_urlfrom specify_cli.authentication.http import github_provider_hostsreturn resolve_github_release_asset_api_url(diff --git a/src/specify_cli/presets/__init__.py b/src/specify_cli/presets/__init__.pyindex b22a44066..eff1e6815 100644--- a/src/specify_cli/presets/__init__.py+++ b/src/specify_cli/presets/__init__.py@@ -4542,7 +4542,7 @@ class PresetCatalog:Passes the ``github`` provider hosts from ``auth.json`` so GitHubEnterprise Server release assets resolve via ``/api/v3``."""- from specify_cli._github_http import resolve_github_release_asset_api_url+ from specify_cli.authentication.github_http import resolve_github_release_asset_api_urlfrom specify_cli.authentication.http import github_provider_hostsreturn resolve_github_release_asset_api_url(diff --git a/src/specify_cli/presets/command_add.py b/src/specify_cli/presets/command_add.pyindex fae04d055..17bb778e9 100644--- a/src/specify_cli/presets/command_add.py+++ b/src/specify_cli/presets/command_add.py@@ -217,7 +217,7 @@ def preset_add(with tempfile.TemporaryDirectory() as tmpdir:archive_path = Path(tmpdir) / "preset.archive"try:- from specify_cli._github_http import (+ from specify_cli.authentication.github_http import (resolve_github_release_asset_api_url,)from specify_cli.authentication.http import github_provider_hostsdiff --git a/src/specify_cli/workflows/_commands.py b/src/specify_cli/workflows/_commands.pyindex 940fa6163..de01789d0 100644--- a/src/specify_cli/workflows/_commands.py+++ b/src/specify_cli/workflows/_commands.py@@ -1165,7 +1165,9 @@ def _install_workflow_from_catalog(try:from specify_cli.authentication.http import open_url as _open_urlfrom specify_cli.authentication.http import github_provider_hosts as _github_provider_hosts- from specify_cli._github_http import resolve_github_release_asset_api_url as _resolve_gh_asset+ from specify_cli.authentication.github_http import (+ resolve_github_release_asset_api_url as _resolve_gh_asset,+ )_wf_cat_extra_headers = None_resolved_workflow_url = _resolve_gh_asset(diff --git a/src/specify_cli/workflows/command_add.py b/src/specify_cli/workflows/command_add.pyindex 774d57515..f123a9645 100644--- a/src/specify_cli/workflows/command_add.py+++ b/src/specify_cli/workflows/command_add.py@@ -303,7 +303,7 @@ def workflow_add(cli.console.print("Cancelled")raise cli.typer.Exit(0)- from specify_cli._github_http import (+ from specify_cli.authentication.github_http import (resolve_github_release_asset_api_url as _resolve_gh_asset,)from specify_cli.authentication.http import (diff --git a/tests/http_helpers.py b/tests/http_helpers.pyindex 04696d7c0..f5bd2e8b0 100644--- a/tests/http_helpers.py+++ b/tests/http_helpers.py@@ -28,7 +28,8 @@ def route_opener_open_through_urlopen(monkeypatch):modules are built on.Delegating ``open()`` to urlopen at call time keeps those patcheseffective; the redirect handler's own behavior is covered by- ``TestRedirectStripping`` in test_authentication.py.+ ``TestRedirectStripping`` in+ ``tests/specify_cli/authentication/test_authentication.py``.Import this fixture into a test module to activate it there."""diff --git a/tests/specify_cli/authentication/__init__.py b/tests/specify_cli/authentication/__init__.pynew file mode 100644index 000000000..7edbe28fb--- /dev/null+++ b/tests/specify_cli/authentication/__init__.py@@ -0,0 +1 @@+"""Tests for the authentication domain."""diff --git a/tests/auth_helpers.py b/tests/specify_cli/authentication/helpers.pysimilarity index 92%rename from tests/auth_helpers.pyrename to tests/specify_cli/authentication/helpers.pyindex babc43e40..2522fcec8 100644--- a/tests/auth_helpers.py+++ b/tests/specify_cli/authentication/helpers.py@@ -1,4 +1,4 @@-"""Shared test helpers for authentication config injection."""+"""Shared authentication-domain test helpers."""from __future__ import annotationsdiff --git a/tests/test_authentication.py b/tests/specify_cli/authentication/test_authentication.pysimilarity index 99%rename from tests/test_authentication.pyrename to tests/specify_cli/authentication/test_authentication.pyindex 38e12edd5..7c8f8b7ef 100644--- a/tests/test_authentication.py+++ b/tests/specify_cli/authentication/test_authentication.py@@ -1,4 +1,4 @@-"""Tests for the authentication provider registry and config-driven HTTP helpers.+"""Tests for the authentication domain registry and config-driven HTTP helpers.Covers:- Config loading (auth.json parsing, validation, permission warning)diff --git a/tests/test_github_http.py b/tests/specify_cli/authentication/test_github_http.pysimilarity index 99%rename from tests/test_github_http.pyrename to tests/specify_cli/authentication/test_github_http.pyindex 6131bacdd..ad6440f79 100644--- a/tests/test_github_http.py+++ b/tests/specify_cli/authentication/test_github_http.py@@ -9,7 +9,7 @@ from urllib.request import Requestimport pytest-from specify_cli._github_http import (+from specify_cli.authentication.github_http import (GITHUB_HOSTS,build_github_request,resolve_github_release_asset_api_url,@@ -47,7 +47,9 @@ class TestBuildGitHubRequest:)def test_malformed_explicit_port_raises_before_request_construction(self, url):"""Malformed explicit ports are rejected before creating a Request."""- with patch("specify_cli._github_http.urllib.request.Request") as request:+ with patch(+ "specify_cli.authentication.github_http.urllib.request.Request"+ ) as request:with pytest.raises(ValueError):build_github_request(url)request.assert_not_called()diff --git a/tests/test_extensions.py b/tests/test_extensions.pyindex 09f1c9203..d2d7d4efd 100644--- a/tests/test_extensions.py+++ b/tests/test_extensions.py@@ -5537,7 +5537,7 @@ class TestExtensionCatalog:return ExtensionCatalog(project_dir)def _inject_github_config(self, monkeypatch, token_env="GH_TOKEN"):- from tests.auth_helpers import inject_github_config+ from tests.specify_cli.authentication.helpers import inject_github_configinject_github_config(monkeypatch, token_env)def test_make_request_no_token_no_auth_header(self, temp_dir, monkeypatch):diff --git a/tests/test_presets.py b/tests/test_presets.pyindex d71bd5258..df9f448ab 100644--- a/tests/test_presets.py+++ b/tests/test_presets.py@@ -2282,7 +2282,7 @@ class TestPresetCatalog:"""Test template catalog functionality."""def _inject_github_config(self, monkeypatch, token_env="GH_TOKEN"):- from tests.auth_helpers import inject_github_config+ from tests.specify_cli.authentication.helpers import inject_github_configinject_github_config(monkeypatch, token_env)def test_default_catalog_url(self, project_dir):diff --git a/tests/test_upgrade.py b/tests/test_upgrade.pyindex edce927e8..513cd2343 100644--- a/tests/test_upgrade.py+++ b/tests/test_upgrade.py@@ -349,7 +349,7 @@ def _capture_request_via_auth_opener():def _inject_github_config(monkeypatch, token_env="GH_TOKEN"):- from tests.auth_helpers import inject_github_config+ from tests.specify_cli.authentication.helpers import inject_github_configinject_github_config(monkeypatch, token_env)