From a111ae763c62043056a3ae504e2cc7520468e75b Mon Sep 17 00:00:00 2001 From: StylusFrost Date: Mon, 1 Jun 2026 20:28:19 +0200 Subject: [PATCH] chore(sdk): tighten get_class docstring and unknown-provider test - Reword get_class docstring: it may populate the _ep_providers cache, rather than claiming "no global state" - Assert ImportError specifically in the unknown-provider test to enforce the public API contract - Drop the unused provider_class_name left over after get_class delegation --- prowler/providers/common/provider.py | 14 ++++---------- .../external/test_dynamic_provider_loading.py | 9 ++++----- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/prowler/providers/common/provider.py b/prowler/providers/common/provider.py index a78cafc147..b0126f2c44 100644 --- a/prowler/providers/common/provider.py +++ b/prowler/providers/common/provider.py @@ -302,13 +302,6 @@ class Provider(ABC): f"it under a different name." ) - # Kept for downstream forks that may extend the dispatch below - # with their own custom built-in branches and reference this name. - # The upstream chain dispatches by `arguments.provider` directly. - provider_class_name = ( - f"{arguments.provider.capitalize()}Provider" # noqa: F841 - ) - fixer_config = load_and_validate_config_file( arguments.provider, arguments.fixer_config ) @@ -689,9 +682,10 @@ class Provider(ABC): def get_class(provider: str) -> type: """Resolve the provider class for a name (built-in or entry-point). - Side-effect-free: no ``sys.exit``, no global state. Collision warnings - are emitted by ``init_global_provider``, not here. The caller handles - errors (CLI exits; the API can return HTTP 400). + Does not call ``sys.exit`` and does not initialize the global + provider (it may populate the ``_ep_providers`` memoization cache). + Collision warnings are emitted by ``init_global_provider``, not here. + The caller handles errors (CLI exits; the API can return HTTP 400). Args: provider: Provider name, e.g. ``"aws"`` or an external plug-in. diff --git a/tests/providers/external/test_dynamic_provider_loading.py b/tests/providers/external/test_dynamic_provider_loading.py index d954a40bdd..aff56c7246 100644 --- a/tests/providers/external/test_dynamic_provider_loading.py +++ b/tests/providers/external/test_dynamic_provider_loading.py @@ -2031,12 +2031,11 @@ class TestGetClass: mock_is_builtin.return_value = False mock_ep.return_value = [] - with pytest.raises((ImportError, Exception)) as exc_info: - Provider.get_class("totally_unknown_xyz_provider") - - # Must NOT be a SystemExit — that belongs in init_global_provider's + # Assert ImportError specifically to enforce the public API contract + # (not a broad Exception). SystemExit belongs in init_global_provider's # wrapper, not in the pure resolver. - assert not isinstance(exc_info.value, SystemExit) + with pytest.raises(ImportError): + Provider.get_class("totally_unknown_xyz_provider") # ----------------------------------------------------------------------- # T4: get_class is PURE for built-ins — no collision warning, no EP call