From 245512d32064401c4f274cfc877d658ce7067be9 Mon Sep 17 00:00:00 2001 From: Sergio Garcia <38561120+sergargar@users.noreply.github.com> Date: Fri, 22 Mar 2024 13:36:21 +0100 Subject: [PATCH] fix(providers): import modules also from outside of directory (#3595) --- prowler/providers/common/common.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/prowler/providers/common/common.py b/prowler/providers/common/common.py index 2f47e91287..d1bee50766 100644 --- a/prowler/providers/common/common.py +++ b/prowler/providers/common/common.py @@ -1,6 +1,7 @@ +import importlib +import pkgutil import sys from importlib import import_module -from pkgutil import iter_modules from prowler.lib.logger import logger @@ -12,8 +13,11 @@ global_provider = None def get_available_providers() -> list[str]: """get_available_providers returns a list of the available providers""" providers = [] - for _, provider, _ in iter_modules([providers_path.replace(".", "/")]): - if provider != "common": + # Dynamically import the package based on its string path + prowler_providers = importlib.import_module(providers_path) + # Iterate over all modules found in the prowler_providers package + for _, provider, ispkg in pkgutil.iter_modules(prowler_providers.__path__): + if provider != "common" and ispkg: providers.append(provider) return providers