Agent: Add plugin_name attribute to puppet's load_plugin

This commit is contained in:
Ilija Lazoroski 2021-12-16 16:26:40 +01:00 committed by Mike Salvatore
parent 8e6abcb795
commit b798255249
3 changed files with 8 additions and 7 deletions

View File

@ -27,9 +27,10 @@ PostBreachData = namedtuple("PostBreachData", ["command", "result"])
class IPuppet(metaclass=abc.ABCMeta): class IPuppet(metaclass=abc.ABCMeta):
@abc.abstractmethod @abc.abstractmethod
def load_plugin(self, plugin: object, plugin_type: PluginType) -> None: def load_plugin(self, plugin_name: str, plugin: object, plugin_type: PluginType) -> None:
""" """
Loads a plugin into the puppet. Loads a plugin into the puppet
:param str plugin_name: The plugin class name
:param object plugin: The plugin object to load :param object plugin: The plugin object to load
:param PluginType plugin_type: The type of plugin being loaded :param PluginType plugin_type: The type of plugin being loaded
""" """

View File

@ -23,11 +23,11 @@ class PluginRegistry:
""" """
self._registry = {} self._registry = {}
def load_plugin(self, plugin: object, plugin_type: PluginType) -> None: def load_plugin(self, plugin_name: str, plugin: object, plugin_type: PluginType) -> None:
self._registry.setdefault(plugin_type, {}) self._registry.setdefault(plugin_type, {})
self._registry[plugin_type][plugin.__class__.__name__] = plugin self._registry[plugin_type][plugin_name] = plugin
logger.debug(f"Plugin '{plugin.__class__.__name__}' loaded") logger.debug(f"Plugin '{plugin_name}' loaded")
def get_plugin(self, plugin_name: str, plugin_type: PluginType) -> Optional[object]: def get_plugin(self, plugin_name: str, plugin_type: PluginType) -> Optional[object]:
try: try:

View File

@ -20,8 +20,8 @@ class Puppet(IPuppet):
def __init__(self) -> None: def __init__(self) -> None:
self._plugin_registry = PluginRegistry() self._plugin_registry = PluginRegistry()
def load_plugin(self, plugin: object, plugin_type: PluginType) -> None: def load_plugin(self, plugin_name: str, plugin: object, plugin_type: PluginType) -> None:
self._plugin_registry.load_plugin(plugin, plugin_type) self._plugin_registry.load_plugin(plugin, plugin_name, plugin_type)
def run_sys_info_collector(self, name: str) -> Dict: def run_sys_info_collector(self, name: str) -> Dict:
pass pass