diff --git a/sekoia_automation/cli.py b/sekoia_automation/cli.py index 611ac2e..de28e49 100644 --- a/sekoia_automation/cli.py +++ b/sekoia_automation/cli.py @@ -186,8 +186,13 @@ def update_sekoia_library( SDKUpdater(modules_path=modules_path).update_sdk_version() +if __name__ == "__main__": + app() + + @app.command(name="run-action") def run_action( + data_path: Path = typer.Option(".", help="Path to the context data"), modules_path: Path = typer.Option(".", help="Path to the playbook modules"), module_name: str = typer.Option(..., help="Name of the module to test"), class_name: str = typer.Option(..., help="Class name of the action to test"), @@ -197,10 +202,6 @@ def run_action( arg.split("=", maxsplit=1)[0]: arg.split("=", maxsplit=1)[1] for arg in args } module_runner = ModuleItemRunner( - module_name=module_name, class_name=class_name, root_path=modules_path + module_name=module_name, class_name=class_name, root_path=modules_path, data_path=data_path ) print(module_runner.run(args=kwargs)) - - -if __name__ == "__main__": - app() diff --git a/sekoia_automation/scripts/action_runner.py b/sekoia_automation/scripts/action_runner.py index f6634a8..61bb548 100644 --- a/sekoia_automation/scripts/action_runner.py +++ b/sekoia_automation/scripts/action_runner.py @@ -12,10 +12,11 @@ class ModuleItemRunner: - def __init__(self, class_name: str, module_name: str, root_path: Path): + def __init__(self, class_name: str, module_name: str, root_path: Path, data_path: Path = Path(".")): self.__class_name = class_name self.__root_path = root_path # `automation-library` folder by default self.__module_path = (root_path / module_name).resolve() + self.__data_path = data_path def load_class_from_path(self, path: Path | str, class_name: str) -> typing.Type: # Add the directory containing the module to sys.path @@ -181,8 +182,8 @@ def run(self, args: dict) -> dict | None: ) module_item = module_item_cls( - module=module, data_path=Path(".") - ) # @todo set custom path? + module=module, data_path=self.__data_path + ) module_item_type = self.get_module_item_type(module_item_cls) if module_item_type == "Action":