diff --git a/lib-injection/build/docker/python/dd-lib-python-init-test-django-27/django_app.py b/lib-injection/build/docker/python/dd-lib-python-init-test-django-27/django_app.py index 94bc2275468..baa3b76f77d 100644 --- a/lib-injection/build/docker/python/dd-lib-python-init-test-django-27/django_app.py +++ b/lib-injection/build/docker/python/dd-lib-python-init-test-django-27/django_app.py @@ -1,12 +1,13 @@ import os import signal import sys +import types -from django.http import HttpResponse +from django.http import HttpRequest, HttpResponse from django.conf.urls import url -def handle_sigterm(signo, sf): +def handle_sigterm(signo: int, sf: types.FrameType | None) -> None: sys.exit(0) @@ -20,7 +21,7 @@ def handle_sigterm(signo, sf): ALLOWED_HOSTS = ["*"] -def index(request): +def index(request: HttpRequest): return HttpResponse("test") diff --git a/lib-injection/build/docker/python/dd-lib-python-init-test-django-gunicorn-alpine/django_app.py b/lib-injection/build/docker/python/dd-lib-python-init-test-django-gunicorn-alpine/django_app.py index 0d16bb91249..1cc276414d2 100644 --- a/lib-injection/build/docker/python/dd-lib-python-init-test-django-gunicorn-alpine/django_app.py +++ b/lib-injection/build/docker/python/dd-lib-python-init-test-django-gunicorn-alpine/django_app.py @@ -1,13 +1,14 @@ import os import signal import sys +import types from django.core.wsgi import get_wsgi_application -from django.http import HttpResponse +from django.http import HttpRequest, HttpResponse from django.urls import path -def handle_sigterm(signo, sf): +def handle_sigterm(signo: int, sf: types.FrameType | None) -> None: sys.exit(0) @@ -20,7 +21,7 @@ def handle_sigterm(signo, sf): ALLOWED_HOSTS = ["*"] -def index(request): +def index(request: HttpRequest): return HttpResponse("test") diff --git a/lib-injection/build/docker/python/dd-lib-python-init-test-django-gunicorn/django_app.py b/lib-injection/build/docker/python/dd-lib-python-init-test-django-gunicorn/django_app.py index 0d16bb91249..1cc276414d2 100644 --- a/lib-injection/build/docker/python/dd-lib-python-init-test-django-gunicorn/django_app.py +++ b/lib-injection/build/docker/python/dd-lib-python-init-test-django-gunicorn/django_app.py @@ -1,13 +1,14 @@ import os import signal import sys +import types from django.core.wsgi import get_wsgi_application -from django.http import HttpResponse +from django.http import HttpRequest, HttpResponse from django.urls import path -def handle_sigterm(signo, sf): +def handle_sigterm(signo: int, sf: types.FrameType | None) -> None: sys.exit(0) @@ -20,7 +21,7 @@ def handle_sigterm(signo, sf): ALLOWED_HOSTS = ["*"] -def index(request): +def index(request: HttpRequest): return HttpResponse("test") diff --git a/lib-injection/build/docker/python/dd-lib-python-init-test-django-preinstalled/django_app.py b/lib-injection/build/docker/python/dd-lib-python-init-test-django-preinstalled/django_app.py index 10d2b06b60b..8b36cfa03b8 100644 --- a/lib-injection/build/docker/python/dd-lib-python-init-test-django-preinstalled/django_app.py +++ b/lib-injection/build/docker/python/dd-lib-python-init-test-django-preinstalled/django_app.py @@ -1,12 +1,13 @@ import os import signal import sys +import types -from django.http import HttpResponse +from django.http import HttpRequest, HttpResponse from django.urls import path -def handle_sigterm(signo, sf): +def handle_sigterm(signo: int, sf: types.FrameType | None) -> None: sys.exit(0) @@ -20,7 +21,7 @@ def handle_sigterm(signo, sf): ALLOWED_HOSTS = ["*"] -def index(request): +def index(request: HttpRequest): import ddtrace if ddtrace.__version__ != "1.12.0": diff --git a/lib-injection/build/docker/python/dd-lib-python-init-test-django-unsupported-package-force/django_app.py b/lib-injection/build/docker/python/dd-lib-python-init-test-django-unsupported-package-force/django_app.py index 77116f1a3f7..780ac3e7b3b 100644 --- a/lib-injection/build/docker/python/dd-lib-python-init-test-django-unsupported-package-force/django_app.py +++ b/lib-injection/build/docker/python/dd-lib-python-init-test-django-unsupported-package-force/django_app.py @@ -1,12 +1,13 @@ import os import signal import sys +import types -from django.http import HttpResponse +from django.http import HttpRequest, HttpResponse from django.urls import path -def handle_sigterm(signo, sf): +def handle_sigterm(signo: int, sf: types.FrameType | None) -> None: sys.exit(0) @@ -20,7 +21,7 @@ def handle_sigterm(signo, sf): ALLOWED_HOSTS = ["*"] -def index(request): +def index(request: HttpRequest): return HttpResponse("test") diff --git a/lib-injection/build/docker/python/dd-lib-python-init-test-django-uvicorn/django_app.py b/lib-injection/build/docker/python/dd-lib-python-init-test-django-uvicorn/django_app.py index 6835b7eff4c..3adcd2dd03b 100644 --- a/lib-injection/build/docker/python/dd-lib-python-init-test-django-uvicorn/django_app.py +++ b/lib-injection/build/docker/python/dd-lib-python-init-test-django-uvicorn/django_app.py @@ -1,13 +1,14 @@ import os import signal import sys +import types from django.core.asgi import get_asgi_application -from django.http import HttpResponse +from django.http import HttpRequest, HttpResponse from django.urls import path -def handle_sigterm(signo, sf): +def handle_sigterm(signo: int, sf: types.FrameType | None) -> None: sys.exit(0) @@ -21,7 +22,7 @@ def handle_sigterm(signo, sf): ALLOWED_HOSTS = ["*"] -def index(request): +def index(request: HttpRequest): return HttpResponse("test") diff --git a/lib-injection/build/docker/python/dd-lib-python-init-test-django/django_app.py b/lib-injection/build/docker/python/dd-lib-python-init-test-django/django_app.py index ac864fb879a..c34fa21ac08 100644 --- a/lib-injection/build/docker/python/dd-lib-python-init-test-django/django_app.py +++ b/lib-injection/build/docker/python/dd-lib-python-init-test-django/django_app.py @@ -3,12 +3,13 @@ import signal import sys import time +import types -from django.http import HttpResponse +from django.http import HttpRequest, HttpResponse from django.urls import path -def handle_sigterm(signo, sf): +def handle_sigterm(signo: int, sf: types.FrameType | None) -> None: sys.exit(0) @@ -22,15 +23,15 @@ def handle_sigterm(signo, sf): ALLOWED_HOSTS = ["*"] -def index(request): +def index(request: HttpRequest): return HttpResponse("test") -def crashme(request): +def crashme(request: HttpRequest): ctypes.string_at(0) -def fork_and_crash(request): +def fork_and_crash(request: HttpRequest): pid = os.fork() if pid > 0: # Parent process @@ -43,7 +44,7 @@ def fork_and_crash(request): return HttpResponse("Nobody should see this") -def child_pids(request): +def child_pids(request: HttpRequest): current_pid = os.getpid() child_pids = [] @@ -71,7 +72,7 @@ def child_pids(request): return HttpResponse(f"Error: {e!s}", status=500, content_type="text/plain") -def zombies(request): +def zombies(request: HttpRequest): zombie_processes = [] # Iterate over all directories in /proc to look for PIDs diff --git a/lib-injection/build/docker/python/dd-lib-python-init-test-protobuf-old/django_app.py b/lib-injection/build/docker/python/dd-lib-python-init-test-protobuf-old/django_app.py index f0660889178..f2904a70bff 100644 --- a/lib-injection/build/docker/python/dd-lib-python-init-test-protobuf-old/django_app.py +++ b/lib-injection/build/docker/python/dd-lib-python-init-test-protobuf-old/django_app.py @@ -1,14 +1,15 @@ import os import signal import sys +import types -from django.http import HttpResponse +from django.http import HttpRequest, HttpResponse from django.urls import path import addressbook_pb2 -def handle_sigterm(signo, sf): +def handle_sigterm(signo: int, sf: types.FrameType | None) -> None: sys.exit(0) @@ -22,7 +23,7 @@ def handle_sigterm(signo, sf): ALLOWED_HOSTS = ["*"] -def index(request): +def index(request: HttpRequest): # Do some stuff with the protobuf person = addressbook_pb2.Person() person.id = 1234 diff --git a/pyproject.toml b/pyproject.toml index 49c3cc72d83..2d28f14892b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -159,7 +159,6 @@ ignore = [ # 2. on each line, comment with the rule name, and a comment, either TODO, or a reason why the rule is ignored "lib-injection/build/docker/python/*" = [ - "ANN001", # missing-type-function-argument "ANN201", # missing-return-type-undocumented-public-function "ARG001", # unused-function-argument "INP001", # implicit-namespace-package @@ -203,8 +202,6 @@ ignore = [ "SIM108", # if-else-block-instead-of-if-exp: ternary operator nay be harder to read on long statements ] "tests/auto_inject/*" = [ - "ANN001", # missing-type-function-argument: TODO - "RUF059", # unused-unpacked-variable: TODO "SLF001", # private-member-access: TODO ] "tests/fuzzer/*" = [ @@ -224,11 +221,9 @@ ignore = [ "S605", # start-process-with-a-shell: test the test needs to run shell commands ] "utils/_context/_scenarios/auto_injection.py" = [ - "ANN001", # missing-type-function-argument: TODO "PLC0415", # import-outside-top-level TODO ] "utils/{_context/_scenarios/docker_ssi.py,docker_ssi/docker_ssi_matrix_utils.py}" = [ - "ANN001", # missing-type-function-argument: TODO "E501", # line-too-long: TODO "T201", # print: TODO "RET504", # unnecessary-assign: TODO @@ -242,11 +237,6 @@ ignore = [ "ANN205" # missing-return-type-static-method: obvious decorators ] "utils/build/*" = ["ALL"] # mostly python weblog code. it may be a good idea to enable rules here -"utils/docker_ssi/*" = [ - "ANN001", # missing-type-function-argument: TODO - "ANN201", # missing-return-type-undocumented-public-function: TODO - "ANN205", # issing-return-type-static-method: TODO -] "utils/{k8s_lib_injection/*,_context/_scenarios/k8s_lib_injection.py}" = [ "ANN003", # missing-type-kwargs: TODO @@ -288,7 +278,6 @@ ignore = [ "UP017", # datetime-timezone-utc: TODO ] "utils/scripts/ssi_wizards/aws_onboarding_wizard_utils.py" = [ - "ANN001", # missing-type-function-argument: TODO "PLR2004", # magic-value-comparison: TODO ] diff --git a/requirements.txt b/requirements.txt index 79c008d855c..7a8fd0a0734 100644 --- a/requirements.txt +++ b/requirements.txt @@ -42,6 +42,7 @@ setuptools==75.8.0 shellcheck-py==0.11.0.1 types-aiofiles==24.1.0.20241221 types-mock==5.2.0.20250924 +types-paramiko==4.0.0.20250822 types-protobuf==5.29.1.20241207 types-python-dateutil==2.9.0.20241206 types-PyYAML==6.0.12.20241230 diff --git a/tests/auto_inject/test_auto_inject_chaos.py b/tests/auto_inject/test_auto_inject_chaos.py index 59479bd55c9..ec71599ba97 100644 --- a/tests/auto_inject/test_auto_inject_chaos.py +++ b/tests/auto_inject/test_auto_inject_chaos.py @@ -7,7 +7,7 @@ class BaseAutoInjectChaos(base.AutoInjectBaseTest): - def _test_removing_things(self, virtual_machine: _VirtualMachine, evil_command): + def _test_removing_things(self, virtual_machine: _VirtualMachine, evil_command: str): """Test break the installation and restore it. After breaking the installation, the app should be still working (but no sending traces to the backend). After breaking the installation, we can restart the app @@ -64,7 +64,7 @@ def _test_removing_things(self, virtual_machine: _VirtualMachine, evil_command): logger.info("Restoring installation using the command:: ") apm_inject_restore = f"{prefix_env} {apm_inject_restore}" logger.info(apm_inject_restore) - _, stdout, stderr = virtual_machine.get_ssh_connection().exec_command(apm_inject_restore) + _, stdout, _stderr = virtual_machine.get_ssh_connection().exec_command(apm_inject_restore) stdout.channel.set_combine_stderr(True) # Read the output line by line diff --git a/tests/auto_inject/test_blocklist_auto_inject.py b/tests/auto_inject/test_blocklist_auto_inject.py index 31dec6c0ac5..54ed76acd66 100644 --- a/tests/auto_inject/test_blocklist_auto_inject.py +++ b/tests/auto_inject/test_blocklist_auto_inject.py @@ -1,4 +1,5 @@ import uuid +import paramiko from scp import SCPClient from utils import scenarios, context, features, irrelevant, logger @@ -8,7 +9,7 @@ class _AutoInjectWorkloadSelectionBaseTest: """Base class to test workload selection policies on auto instrumentation.""" - def _execute_remote_command(self, ssh_client, command): + def _execute_remote_command(self, ssh_client: paramiko.SSHClient, command: str): """Execute remote command and get remote log file from the vm. You can use this method using env variables or using injection config file""" unique_log_name = f"host_injection_{uuid.uuid4()}.log" diff --git a/tests/auto_inject/utils.py b/tests/auto_inject/utils.py index e1b04c889da..ba951965425 100644 --- a/tests/auto_inject/utils.py +++ b/tests/auto_inject/utils.py @@ -1,4 +1,5 @@ import time +import paramiko from utils.onboarding.weblog_interface import make_get_request, warmup_weblog, make_internal_get_request from utils.onboarding.backend_interface import wait_backend_trace_id from utils.onboarding.wait_for_tcp_port import wait_for_port @@ -10,7 +11,12 @@ class AutoInjectBaseTest: def _test_install( - self, virtual_machine, *, profile: bool = False, appsec: bool = False, origin_detection: bool = False + self, + virtual_machine: _VirtualMachine, + *, + profile: bool = False, + appsec: bool = False, + origin_detection: bool = False, ): """If there is a multicontainer app, we need to make a request to each app""" @@ -32,7 +38,7 @@ def _test_install( def _check_install( self, virtual_machine: _VirtualMachine, - vm_context_url, + vm_context_url: str, *, profile: bool = False, appsec: bool = False, @@ -75,7 +81,7 @@ def _check_install( self._log_trace_debug_message(e, request_uuid) raise - def _appsec_validator(self, _, trace_data): + def _appsec_validator(self, _: str, trace_data: dict): """Validator for Appsec traces that checks if the trace contains an Appsec event.""" root_id = trace_data["trace"]["root_id"] root_span = trace_data["trace"]["spans"][root_id] @@ -102,7 +108,7 @@ def _appsec_validator(self, _, trace_data): logger.error("expected 'appsec.event' to be true in trace meta or at least one rule triggered") return False - def _container_tags_validator(self, _, trace_data): + def _container_tags_validator(self, _: str, trace_data: dict): root_id = trace_data["trace"]["root_id"] root_span = trace_data["trace"]["spans"][root_id] @@ -127,14 +133,14 @@ def _log_trace_debug_message(self, exc: Exception, request_uuid: str) -> None: f"- A problem processing the intake in the backend (manually locate the trace id [{request_uuid}] in the DD console, using the system-tests organization)\n" ) - def close_channel(self, channel) -> None: + def close_channel(self, channel: paramiko.Channel) -> None: try: if not channel.eof_received: channel.close() except Exception as e: logger.error(f"Error closing the channel: {e}") - def execute_command(self, virtual_machine, command) -> str: + def execute_command(self, virtual_machine: _VirtualMachine, command: str) -> str: # Env for the command prefix_env = "" for key, value in virtual_machine.get_command_environment().items(): @@ -165,7 +171,12 @@ def execute_command(self, virtual_machine, command) -> str: return command_output def _test_uninstall_commands( - self, virtual_machine, stop_weblog_command, start_weblog_command, uninstall_command, install_command + self, + virtual_machine: _VirtualMachine, + stop_weblog_command: str, + start_weblog_command: str, + uninstall_command: str, + install_command: str, ): """We can unistall the auto injection software. We can start the app again The weblog app should work but no sending traces to the backend. @@ -228,7 +239,7 @@ def _test_uninstall_commands( self._test_install(virtual_machine) logger.info(f"Success _test_uninstall for : [{virtual_machine.name}]") - def _test_uninstall(self, virtual_machine): + def _test_uninstall(self, virtual_machine: _VirtualMachine): header = "----------------------------------------------------------------------" vm_logger(context.scenario.host_log_folder, virtual_machine.name).info( f"{header} \n {header} \n Launching the uninstall for VM: {virtual_machine.name} \n {header} \n {header}" @@ -250,7 +261,7 @@ def _test_uninstall(self, virtual_machine): virtual_machine, stop_weblog_command, start_weblog_command, uninstall_command, install_command ) - def _test_no_world_writeable(self, virtual_machine): + def _test_no_world_writeable(self, virtual_machine: _VirtualMachine): """Checks that there are no world writeable files in /opt/datadog-packages/datadog-apm*""" logger = vm_logger(context.scenario.host_log_folder, virtual_machine.name) logger.info( diff --git a/utils/_context/_scenarios/__init__.py b/utils/_context/_scenarios/__init__.py index d7276419b02..39461ff8357 100644 --- a/utils/_context/_scenarios/__init__.py +++ b/utils/_context/_scenarios/__init__.py @@ -1094,7 +1094,7 @@ class _Scenarios: "DOCKER_SSI_APPSEC", doc="Validates the installer and the ssi on a docker environment", extra_env_vars={"DD_SERVICE": "payments-service"}, - appsec_enabled="true", + appsec_enabled=True, scenario_groups=[scenario_groups.all, scenario_groups.docker_ssi], ) docker_ssi_crashtracking = DockerSSIScenario( diff --git a/utils/_context/_scenarios/auto_injection.py b/utils/_context/_scenarios/auto_injection.py index cbbf8b25ec5..874432e8cda 100644 --- a/utils/_context/_scenarios/auto_injection.py +++ b/utils/_context/_scenarios/auto_injection.py @@ -7,7 +7,7 @@ from utils._logger import logger from utils.onboarding.debug_vm import download_vm_logs from utils.virtual_machine.virtual_machines import _VirtualMachine, load_virtual_machines -from .core import Scenario +from .core import Scenario, ScenarioGroup class _VirtualMachineScenario(Scenario): @@ -19,10 +19,10 @@ def __init__( *, github_workflow: str, doc: str, - vm_provision=None, - agent_env=None, - app_env=None, - scenario_groups=None, + vm_provision: str | None = None, + agent_env: dict | None = None, + app_env: dict | None = None, + scenario_groups: list[ScenarioGroup] | None = None, ) -> None: super().__init__(name, doc=doc, github_workflow=github_workflow, scenario_groups=scenario_groups) self.vm_provision_name = vm_provision @@ -153,7 +153,7 @@ def fill_context(self): # different version del self.components[key] - def pytest_sessionfinish(self, session, exitstatus): # noqa: ARG002 + def pytest_sessionfinish(self, session: pytest.Session, exitstatus: int) -> None: # noqa: ARG002 self.close_targets() def close_targets(self): @@ -227,13 +227,13 @@ def customize_feature_parity_dashboard(self, result: dict): class InstallerAutoInjectionScenario(_VirtualMachineScenario): def __init__( self, - name, - doc, - vm_provision="installer-auto-inject", - agent_env=None, - app_env=None, - scenario_groups=None, - github_workflow=None, + name: str, + doc: str, + vm_provision: str = "installer-auto-inject", + agent_env: dict | None = None, + app_env: dict | None = None, + scenario_groups: list[ScenarioGroup] | None = None, + github_workflow: str | None = None, ) -> None: # Force full tracing without limits app_env_defaults = { diff --git a/utils/_context/_scenarios/docker_ssi.py b/utils/_context/_scenarios/docker_ssi.py index 87238daff7e..f7daf1bbc61 100644 --- a/utils/_context/_scenarios/docker_ssi.py +++ b/utils/_context/_scenarios/docker_ssi.py @@ -3,6 +3,7 @@ import random import socket import time +from collections.abc import Iterator from docker.errors import BuildError from docker.models.networks import Network import pytest @@ -20,7 +21,7 @@ from utils._logger import logger from utils.virtual_machine.vm_logger import vm_logger -from .core import Scenario +from .core import Scenario, ScenarioGroup class ContainerRemovalError(Exception): @@ -37,7 +38,13 @@ class DockerSSIScenario(Scenario): _network: Network = None def __init__( - self, name, doc, extra_env_vars: dict | None = None, scenario_groups=None, appsec_enabled=None + self, + name: str, + doc: str, + extra_env_vars: dict | None = None, + scenario_groups: list[ScenarioGroup] | None = None, + *, + appsec_enabled: bool | None = None, ) -> None: super().__init__(name, doc=doc, github_workflow="dockerssi", scenario_groups=scenario_groups) @@ -110,7 +117,7 @@ def configure(self, config: pytest.Config): self._env, self._custom_library_version, self._custom_injector_version, - self._appsec_enabled, + appsec_enabled=self._appsec_enabled, ) self.ssi_image_builder.configure() self.ssi_image_builder.build_weblog() @@ -152,7 +159,7 @@ def fix_gitlab_network(self): self.agent_host = self._agent_container.network_ip(self._network) logger.debug(f"GITLAB_CI: Set agent host to {self.agent_host}") - def pytest_sessionfinish(self, session, exitstatus): # noqa: ARG002 + def pytest_sessionfinish(self, session: pytest.Session, exitstatus: int) -> None: # noqa: ARG002 self.close_targets() def close_targets(self): @@ -186,33 +193,33 @@ def find_image_name(self, image: str, architecture: str) -> str | None: return None - def fill_context(self, json_tested_components): + def fill_context(self, json_tested_components: dict): """After extract the components from the weblog, fill the context with the data""" image_internal_name = self.find_image_name(self._base_image, self._arch) self.configuration["os"] = image_internal_name self.configuration["arch"] = self._arch.replace("linux/", "") - for key in json_tested_components: + for key, value in json_tested_components.items(): try: self.components[key] = ComponentVersion( key.removeprefix("datadog-apm-library-"), - json_tested_components[key].lstrip(" "), + value.lstrip(" "), ).version except ValueError: - self.components[key] = json_tested_components[key].lstrip(" ") - if key == "weblog_url" and json_tested_components[key]: - self.weblog_url = json_tested_components[key].lstrip(" ") + self.components[key] = value.lstrip(" ") + if key == "weblog_url" and value: + self.weblog_url = value.lstrip(" ") continue - if key == "runtime_version" and json_tested_components[key]: - self._installed_language_runtime = Version(json_tested_components[key].lstrip(" ")) + if key == "runtime_version" and value: + self._installed_language_runtime = Version(value.lstrip(" ")) # Runtime version is stored as configuration not as dependency del self.components[key] self.configuration["runtime_version"] = f"{self._installed_language_runtime}" - if key.startswith("datadog-apm-inject") and json_tested_components[key]: - self._datadog_apm_inject_version = f"v{json_tested_components[key].lstrip(' ')}" + if key.startswith("datadog-apm-inject") and value: + self._datadog_apm_inject_version = f"v{value.lstrip(' ')}" if key.startswith("datadog-apm-library-") and self.components[key]: - library_version_number = json_tested_components[key].lstrip(" ") + library_version_number = value.lstrip(" ") self._libray_version = ComponentVersion(self._library, str(library_version_number)) # We store without the lang sufix self.components["datadog-apm-library"] = self.components[key] @@ -254,7 +261,7 @@ def check_installed_components(self): raise ValueError("❌ Error: Could not get the library or injector version. ❌") logger.stdout("✅ All components are installed correctly. ✅") - def post_setup(self, session): # noqa: ARG002 + def post_setup(self, session: pytest.Session) -> None: # noqa: ARG002 self.check_installed_components() logger.stdout("--- Waiting for all traces and telemetry to be sent to test agent ---") @@ -289,19 +296,20 @@ class DockerSSIImageBuilder: def __init__( self, - scenario_name, - host_log_folder, - base_weblog, - base_image, - library, - arch, - installable_runtime, - push_base_images, - force_build, - env, - custom_library_version, - custom_injector_version, - appsec_enabled=None, + scenario_name: str, + host_log_folder: str, + base_weblog: str, + base_image: str, + library: str, + arch: str, + installable_runtime: str | None, + push_base_images: bool, # noqa: FBT001 + force_build: bool, # noqa: FBT001 + env: str, + custom_library_version: str | None, + custom_injector_version: str | None, + *, + appsec_enabled: bool | None = None, ) -> None: self.scenario_name = scenario_name self.host_log_folder = host_log_folder @@ -460,7 +468,7 @@ def build_ssi_installer_image(self): self.print_docker_build_logs("Error building installer docker file", e.build_log) raise BuildError("Failed to build installer docker image", e.build_log) from e - def build_weblog_image(self, ssi_installer_docker_tag): + def build_weblog_image(self, ssi_installer_docker_tag: str): """Build the final weblog image. Uses base ssi installer image, install the full ssi (to perform the auto inject) and build the weblog image """ @@ -485,7 +493,9 @@ def build_weblog_image(self, ssi_installer_docker_tag): "SSI_ENV": self._env, "DD_INSTALLER_LIBRARY_VERSION": self._custom_library_version, "DD_INSTALLER_INJECTOR_VERSION": self._custom_injector_version, - "DD_APPSEC_ENABLED": self._appsec_enabled, + "DD_APPSEC_ENABLED": str(self._appsec_enabled).lower() + if isinstance(self._appsec_enabled, bool) + else None, }, ) self.print_docker_build_logs(self.ssi_all_docker_tag, build_logs) @@ -519,7 +529,7 @@ def tested_components(self): logger.info(f"Testes components: {result.decode('utf-8')}") return json.loads(result.decode("utf-8").replace("'", '"')) - def print_docker_build_logs(self, image_tag, build_logs): + def print_docker_build_logs(self, image_tag: str, build_logs: Iterator[dict[str, str]]): """Print the docker build logs to docker_build.log file""" vm_logger(self.host_log_folder, "docker_build", log_folder=self.host_log_folder).info( "***************************************************************" @@ -536,7 +546,7 @@ def print_docker_build_logs(self, image_tag, build_logs): for line in chunk["stream"].splitlines(): vm_logger(self.host_log_folder, "docker_build", log_folder=self.host_log_folder).info(line) - def print_docker_push_logs(self, image_tag, push_logs): + def print_docker_push_logs(self, image_tag: str, push_logs: str): """Print the docker push logs to docker_push.log file""" vm_logger(self.host_log_folder, "docker_push", log_folder=self.host_log_folder).info( "***************************************************************" diff --git a/utils/docker_ssi/docker_ssi_definitions.py b/utils/docker_ssi/docker_ssi_definitions.py index 28e5cf16abf..daffda22c5b 100644 --- a/utils/docker_ssi/docker_ssi_definitions.py +++ b/utils/docker_ssi/docker_ssi_definitions.py @@ -19,7 +19,7 @@ class JavaRuntimeInstallableVersions: JAVA_11 = RuntimeInstallableVersion("JAVA_11", "11.0.27-zulu") @staticmethod - def get_all_versions(): + def get_all_versions() -> list["RuntimeInstallableVersion"]: return [ JavaRuntimeInstallableVersions.JAVA_24, JavaRuntimeInstallableVersions.JAVA_21, @@ -28,7 +28,7 @@ def get_all_versions(): ] @staticmethod - def get_version_id(version): + def get_version_id(version: str) -> str: for version_check in JavaRuntimeInstallableVersions.get_all_versions(): if version_check.version == version: return version_check.version_id @@ -50,7 +50,7 @@ class PHPRuntimeInstallableVersions: PHP83 = RuntimeInstallableVersion("PHP83", "8.3") @staticmethod - def get_all_versions(): + def get_all_versions() -> list["RuntimeInstallableVersion"]: return [ PHPRuntimeInstallableVersions.PHP56, PHPRuntimeInstallableVersions.PHP70, @@ -65,7 +65,7 @@ def get_all_versions(): ] @staticmethod - def get_version_id(version): + def get_version_id(version: str) -> str: for version_check in PHPRuntimeInstallableVersions.get_all_versions(): if version_check.version == version: return version_check.version_id @@ -84,7 +84,7 @@ class PythonRuntimeInstallableVersions: PY312 = RuntimeInstallableVersion("PY312", "3.12.7") @staticmethod - def get_all_versions(): + def get_all_versions() -> list["RuntimeInstallableVersion"]: return [ PythonRuntimeInstallableVersions.PY36, PythonRuntimeInstallableVersions.PY37, @@ -96,7 +96,7 @@ def get_all_versions(): ] @staticmethod - def get_version_id(version): + def get_version_id(version: str) -> str: for version_check in PythonRuntimeInstallableVersions.get_all_versions(): if version_check.version == version: return version_check.version_id @@ -122,7 +122,7 @@ class JSRuntimeInstallableVersions: JS2303 = RuntimeInstallableVersion("JS2303", "23.3") @staticmethod - def get_all_versions(): + def get_all_versions() -> list["RuntimeInstallableVersion"]: return [ JSRuntimeInstallableVersions.JS1200, JSRuntimeInstallableVersions.JS1222, @@ -141,7 +141,7 @@ def get_all_versions(): ] @staticmethod - def get_version_id(version): + def get_version_id(version: str) -> str: for version_check in JSRuntimeInstallableVersions.get_all_versions(): if version_check.version == version: return version_check.version_id @@ -156,7 +156,7 @@ class DotnetRuntimeInstallableVersions: DOTNET60 = RuntimeInstallableVersion("DOTNET60", "6.0.428") @staticmethod - def get_all_versions(): + def get_all_versions() -> list["RuntimeInstallableVersion"]: return [ DotnetRuntimeInstallableVersions.DOTNET80, DotnetRuntimeInstallableVersions.DOTNET70, @@ -164,7 +164,7 @@ def get_all_versions(): ] @staticmethod - def get_version_id(version): + def get_version_id(version: str) -> str: for version_check in DotnetRuntimeInstallableVersions.get_all_versions(): if version_check.version == version: return version_check.version_id @@ -183,7 +183,7 @@ class RubyRuntimeInstallableVersions: RB34 = RuntimeInstallableVersion("RB34", "3.4.7") @staticmethod - def get_all_versions(): + def get_all_versions() -> list["RuntimeInstallableVersion"]: return [ RubyRuntimeInstallableVersions.RB26, RubyRuntimeInstallableVersions.RB27, @@ -195,7 +195,7 @@ def get_all_versions(): ] @staticmethod - def get_version_id(version): + def get_version_id(version: str) -> str: for version_check in RubyRuntimeInstallableVersions.get_all_versions(): if version_check.version == version: return version_check.version_id diff --git a/utils/docker_ssi/docker_ssi_matrix_utils.py b/utils/docker_ssi/docker_ssi_matrix_utils.py index 9571b7d36fc..e130640150a 100644 --- a/utils/docker_ssi/docker_ssi_matrix_utils.py +++ b/utils/docker_ssi/docker_ssi_matrix_utils.py @@ -8,7 +8,7 @@ ) -def resolve_runtime_version(library, runtime): +def resolve_runtime_version(library: str, runtime: str) -> str: """For installable runtimes, get the version identifier. ie JAVA_11""" if library == "java": return JavaRuntimeInstallableVersions.get_version_id(runtime) diff --git a/utils/scripts/ssi_wizards/aws_onboarding_wizard_utils.py b/utils/scripts/ssi_wizards/aws_onboarding_wizard_utils.py index 30132bdac0b..44fa2b61fcb 100644 --- a/utils/scripts/ssi_wizards/aws_onboarding_wizard_utils.py +++ b/utils/scripts/ssi_wizards/aws_onboarding_wizard_utils.py @@ -2,7 +2,7 @@ from pathlib import Path -def extract_private_key(file_path) -> None: +def extract_private_key(file_path: str | Path) -> None: try: file_path = Path(file_path).resolve() # Convert to absolute path