feat(sdk): add Provider.get_class dynamic provider resolver#11398
Open
StylusFrost wants to merge 5 commits into
Open
Conversation
- Add public get_class() resolving built-in and entry-point providers - Refactor init_global_provider to use it; collision warning stays there - Refactor get_providers_help_text to use it
…PROWLER-1771-public-dynamic-provider-class-resolver # Conflicts: # prowler/CHANGELOG.md
…PROWLER-1771-public-dynamic-provider-class-resolver # Conflicts: # prowler/CHANGELOG.md
…PROWLER-1771-public-dynamic-provider-class-resolver # Conflicts: # prowler/CHANGELOG.md
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Part of the Dynamic Providers (API) epic (PROWLER-1472) — task PROWLER-1771, the first slice toward decoupling the API from hardcoded provider types.
The SDK already discovers providers dynamically via entry points (PROWLER-1391, #10700), but the class-resolution logic ("given a provider name, return its provider class") lived inline inside
init_global_provider(which sets global state and callssys.exit) andget_providers_help_text. There was no public, side-effect-free API the Django API could call, forcing it to keep a hardcodedmatchover provider types.Description
Provider.get_class(provider)resolving a provider class by name for both built-in (direct import) and external entry-point providers. Side-effect-free: noset_global_provider, nosys.exit; the caller decides error handling (CLI exits, the API can return HTTP 400).init_global_providerto use it, preserving CLI behavior: a built-in's missing transitive dependency still logs critical +sys.exit(1). The collision warning (built-in wins over a same-named plug-in) stays here, at the point of use, soprowler --helpno longer emits it spuriously.get_providers_help_textto use it.Steps to review
uv run pytest tests/providers/external/test_dynamic_provider_loading.py -v(97 passing, incl. newTestGetClass).Provider.get_class("aws")returnsAwsProvider; an external entry-point provider resolves to its class; an unknown name raisesImportError(neversys.exit).prowler --helpemits no spurious collision warnings.Checklist
SDK/CLI
License
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.