diff --git a/plugins/python_3_script/.CHECKSUM b/plugins/python_3_script/.CHECKSUM index cda27db19a..9690e3a005 100644 --- a/plugins/python_3_script/.CHECKSUM +++ b/plugins/python_3_script/.CHECKSUM @@ -1,5 +1,5 @@ { - "spec": "441f83b7f97f94804c7ae6ef98300add", + "spec": "c7ff086482db33567e135d3bc4f41537", "manifest": "2c538fa19b6b5693104e6c71a09859e2", "setup": "750744ab1e4d406ce443a91abe0c288d", "schemas": [ diff --git a/plugins/python_3_script/Dockerfile b/plugins/python_3_script/Dockerfile index 4c0ad6ddb0..cf9149190e 100755 --- a/plugins/python_3_script/Dockerfile +++ b/plugins/python_3_script/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=linux/amd64 rapid7/insightconnect-python-3-slim-plugin:6.1.1 +FROM --platform=linux/amd64 rapid7/insightconnect-python-3-slim-plugin:6.1.2 LABEL organization=rapid7 LABEL sdk=python diff --git a/plugins/python_3_script/icon_python_3_script/connection/connection.py b/plugins/python_3_script/icon_python_3_script/connection/connection.py index 5070f2a1fe..a85a6612c8 100755 --- a/plugins/python_3_script/icon_python_3_script/connection/connection.py +++ b/plugins/python_3_script/icon_python_3_script/connection/connection.py @@ -1,3 +1,4 @@ +import sys import os from subprocess import CalledProcessError, TimeoutExpired, check_output, run # noqa: B404 @@ -5,6 +6,7 @@ from insightconnect_plugin_runtime.exceptions import ConnectionTestException from .schema import ConnectionSchema, Input +from typing import Dict, Any class Connection(insightconnect_plugin_runtime.Connection): @@ -13,50 +15,47 @@ def __init__(self): self.dependencies, self.timeout = None, None self.script_credentials = None - def connect(self, params={}): - self.timeout = params.get(Input.TIMEOUT) - self.dependencies = params.get(Input.MODULES) + def connect(self, params={}) -> None: + self.timeout = params.get(Input.TIMEOUT, 60) + self.dependencies = params.get(Input.MODULES, []) self.script_credentials = { "username": params.get(Input.SCRIPT_USERNAME_AND_PASSWORD, {}).get("username"), "password": params.get(Input.SCRIPT_USERNAME_AND_PASSWORD, {}).get("password"), "secret_key": params.get(Input.SCRIPT_SECRET_KEY, {}).get("secretKey"), } - def test(self): - connection_test_output = {"success": True} - + def test(self) -> Dict[str, Any]: self.logger.info("[*] Performing Python version check...") - check = str(check_output(["python", "--version"]), "utf-8") # noqa: B607,B603 - self.logger.info(check) + python_version = str(check_output(["python", "--version"]), "utf-8") # noqa: B607,B603 + self.logger.info(python_version) - if "Python 3." not in check: + if "Python 3." not in python_version: raise ConnectionTestException(cause="[-] Python 3 is not installed correctly") - if not self.dependencies: - return connection_test_output - - self.logger.info(f"[*] Installing user-specified dependencies ({self.dependencies})...") - self.install_dependencies() - self.logger.info("[*] Dependencies installed!\n") - return connection_test_output + if self.dependencies: + self.logger.info(f"[*] Installing user-specified dependencies ({self.dependencies})...") + self.install_dependencies() + self.logger.info("[*] Dependencies installed!\n") + return {"success": True} @staticmethod - def _set_pythonuserbase(): + def _set_python_userbase() -> None: os.environ.update({"PYTHONUSERBASE": "/var/cache/python_dependencies"}) - def install_dependencies(self): - dependencies = " ".join(self.dependencies) - command = f"pip install --user {dependencies}" - - self._set_pythonuserbase() - + def install_dependencies(self) -> None: + self._set_python_userbase() try: - run(args=command.split(" "), capture_output=True, timeout=self.timeout, check=True) # noqa: B603 + run( # noqa: B603 + args=[sys.executable, "-m", "pip", "install"] + self.dependencies, + capture_output=True, + timeout=self.timeout, + check=True, + ) except TimeoutExpired: raise ConnectionTestException( cause="Error: Installing Python dependencies exceeded timeout", assistance="Consider increasing timeout" ) except CalledProcessError as error: raise ConnectionTestException( - cause=f"Error: Non-zero exit code returned. Message: {error.output.decode('UTF8')}" + cause=f"Error: Non-zero exit code returned. Message: {error.output.decode('utf-8')}" ) diff --git a/plugins/python_3_script/plugin.spec.yaml b/plugins/python_3_script/plugin.spec.yaml index 0ffde5b805..30b4608957 100644 --- a/plugins/python_3_script/plugin.spec.yaml +++ b/plugins/python_3_script/plugin.spec.yaml @@ -13,7 +13,7 @@ supported_versions: ["Python 3.9.19"] fedramp_ready: true sdk: type: slim - version: 6.1.1 + version: 6.1.2 user: root packages: - libxslt-dev