Skip to content

feat(sdk): add Provider.get_class dynamic provider resolver#11398

Open
StylusFrost wants to merge 5 commits into
PROWLER-1391-provider-contract-dynamic-discoveryfrom
PROWLER-1771-public-dynamic-provider-class-resolver
Open

feat(sdk): add Provider.get_class dynamic provider resolver#11398
StylusFrost wants to merge 5 commits into
PROWLER-1391-provider-contract-dynamic-discoveryfrom
PROWLER-1771-public-dynamic-provider-class-resolver

Conversation

@StylusFrost
Copy link
Copy Markdown
Contributor

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 calls sys.exit) and get_providers_help_text. There was no public, side-effect-free API the Django API could call, forcing it to keep a hardcoded match over provider types.

Stacked PR: this targets PROWLER-1391-provider-contract-dynamic-discovery (#10700), not master, because it builds on the dynamic-discovery helpers introduced there. Merge #10700 first.

Description

  • Add public Provider.get_class(provider) resolving a provider class by name for both built-in (direct import) and external entry-point providers. Side-effect-free: no set_global_provider, no sys.exit; the caller decides error handling (CLI exits, the API can return HTTP 400).
  • Refactor init_global_provider to 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, so prowler --help no longer emits it spuriously.
  • Refactor get_providers_help_text to use it.

Steps to review

  • uv run pytest tests/providers/external/test_dynamic_provider_loading.py -v (97 passing, incl. new TestGetClass).
  • Provider.get_class("aws") returns AwsProvider; an external entry-point provider resolves to its class; an unknown name raises ImportError (never sys.exit).
  • prowler --help emits no spurious collision warnings.

Checklist

  • Review if the code is being covered by tests.
  • Review if code is being documented following the Google Python style guide.
  • Review if backport is needed.
  • Review if is needed to change the Readme.md
  • Ensure new entries are added to CHANGELOG.md, if applicable.

SDK/CLI

  • Are there new checks included in this PR? No

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

- 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
@StylusFrost StylusFrost requested a review from a team as a code owner May 31, 2026 16:56
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant