diff --git a/gvm/protocols/gmp/_gmpnext.py b/gvm/protocols/gmp/_gmpnext.py index 642a83045..631bf3215 100644 --- a/gvm/protocols/gmp/_gmpnext.py +++ b/gvm/protocols/gmp/_gmpnext.py @@ -12,7 +12,8 @@ from ._gmp227 import GMPv227 from .requests.next import ( AgentGroups, - AgentInstallers, + AgentInstallerInstructionLanguageType, + AgentInstallerInstructions, Agents, Credentials, CredentialStoreCredentialType, @@ -55,52 +56,25 @@ class GMPNext(GMPv227[T]): def get_protocol_version() -> tuple[int, int]: return (22, 8) - def get_agent_installers( + def get_agent_installer_instruction( self, *, - filter_string: str | None = None, - filter_id: EntityID | None = None, - trash: bool | None = None, - details: bool | None = None, + scanner_id: EntityID, + language_type: AgentInstallerInstructionLanguageType, ) -> T: - """Request a list of agent installers + """Request an agent installer instruction. Args: - filter_string: Filter term to use for the query - filter_id: UUID of an existing filter to use for the query - trash: Whether to get the trashcan agent installers instead - details: Whether to include extra details like tasks using this - scanner + scanner_id: UUID of the Agent controller to get the installer instruction for. + language_type: Language of the installer instruction. """ return self._send_request_and_transform_response( - AgentInstallers.get_agent_installers( - filter_string=filter_string, - filter_id=filter_id, - trash=trash, - details=details, + AgentInstallerInstructions.get_agent_installer_instruction( + scanner_id=scanner_id, + language_type=language_type, ) ) - def get_agent_installer(self, agent_installer_id: EntityID) -> T: - """Request a single agent installer - - Args: - agent_installer_id: UUID of an existing agent installer - """ - return self._send_request_and_transform_response( - AgentInstallers.get_agent_installer(agent_installer_id) - ) - - def get_agent_installer_file(self, agent_installer_id: EntityID) -> T: - """Request a single agent installer file - - Args: - agent_installer_id: UUID of an existing agent installer - """ - return self._send_request_and_transform_response( - AgentInstallers.get_agent_installer_file(agent_installer_id) - ) - def get_agents( self, *, diff --git a/gvm/protocols/gmp/requests/next/__init__.py b/gvm/protocols/gmp/requests/next/__init__.py index 71c2cd286..593f37e0b 100644 --- a/gvm/protocols/gmp/requests/next/__init__.py +++ b/gvm/protocols/gmp/requests/next/__init__.py @@ -3,7 +3,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later from gvm.protocols.gmp.requests.next._agent_groups import AgentGroups -from gvm.protocols.gmp.requests.next._agent_installers import AgentInstallers +from gvm.protocols.gmp.requests.next._agent_installer_instructions import ( + AgentInstallerInstructionLanguageType, + AgentInstallerInstructions, +) from gvm.protocols.gmp.requests.next._agents import Agents from gvm.protocols.gmp.requests.next._credential_stores import CredentialStores from gvm.protocols.gmp.requests.next._credentials import ( @@ -115,7 +118,8 @@ __all__ = ( "AgentGroups", - "AgentInstallers", + "AgentInstallerInstructionLanguageType", + "AgentInstallerInstructions", "Agents", "AggregateStatistic", "Aggregates", diff --git a/gvm/protocols/gmp/requests/next/_agent_installer_instructions.py b/gvm/protocols/gmp/requests/next/_agent_installer_instructions.py new file mode 100644 index 000000000..966b62d0e --- /dev/null +++ b/gvm/protocols/gmp/requests/next/_agent_installer_instructions.py @@ -0,0 +1,43 @@ +from enum import Enum + +from gvm.errors import RequiredArgument +from gvm.protocols.core import Request +from gvm.protocols.gmp.requests._entity_id import EntityID +from gvm.xml import XmlCommand + + +class AgentInstallerInstructionLanguageType(Enum): + EN = "en" + DE = "de" + + +class AgentInstallerInstructions: + @classmethod + def get_agent_installer_instruction( + cls, + scanner_id: EntityID, + language_type: AgentInstallerInstructionLanguageType, + ) -> Request: + """Request an agent installer instruction. + + Args: + scanner_id: UUID of the Agent controller to get the installer instruction for. + language_type: Language of the installer instruction. + """ + if not scanner_id: + raise RequiredArgument( + function=cls.get_agent_installer_instruction.__name__, + argument="scanner_id", + ) + + if not language_type: + raise RequiredArgument( + function=cls.get_agent_installer_instruction.__name__, + argument="language_type", + ) + + cmd = XmlCommand("get_agent_installer_instruction") + cmd.set_attribute("scanner_id", str(scanner_id)) + cmd.set_attribute("language", language_type.value) + + return cmd diff --git a/gvm/protocols/gmp/requests/next/_agent_installers.py b/gvm/protocols/gmp/requests/next/_agent_installers.py deleted file mode 100644 index fae64c559..000000000 --- a/gvm/protocols/gmp/requests/next/_agent_installers.py +++ /dev/null @@ -1,81 +0,0 @@ -# SPDX-FileCopyrightText: 2025 Greenbone AG -# -# SPDX-License-Identifier: GPL-3.0-or-later -# -# SPDX-License-Identifier: GPL-3.0-or-later - - -from gvm.errors import RequiredArgument -from gvm.protocols.core import Request -from gvm.protocols.gmp.requests._entity_id import EntityID -from gvm.utils import to_bool -from gvm.xml import XmlCommand - - -class AgentInstallers: - @staticmethod - def get_agent_installers( - *, - filter_string: str | None = None, - filter_id: EntityID | None = None, - trash: bool | None = None, - details: bool | None = None, - ) -> Request: - """Request a list of agent installers - - Args: - filter_string: Filter term to use for the query - filter_id: UUID of an existing filter to use for the query - trash: Whether to get the trashcan agent installers instead - details: Whether to include extra details like tasks using this - scanner - """ - cmd = XmlCommand("get_agent_installers") - cmd.add_filter(filter_string, filter_id) - - if trash is not None: - cmd.set_attribute("trash", to_bool(trash)) - - if details is not None: - cmd.set_attribute("details", to_bool(details)) - - return cmd - - @classmethod - def get_agent_installer(cls, agent_installer_id: EntityID) -> Request: - """Request a single agent installer - - Args: - agent_installer_id: UUID of an existing agent installer - """ - if not agent_installer_id: - raise RequiredArgument( - function=cls.get_agent_installer.__name__, - argument="agent_installer_id", - ) - - cmd = XmlCommand("get_agent_installers") - cmd.set_attribute("agent_installer_id", str(agent_installer_id)) - - # for single entity always request all details - cmd.set_attribute("details", "1") - - return cmd - - @classmethod - def get_agent_installer_file(cls, agent_installer_id: EntityID) -> Request: - """Request a single agent installer - - Args: - agent_installer_id: UUID of an existing agent installer - """ - if not agent_installer_id: - raise RequiredArgument( - function=cls.get_agent_installer.__name__, - argument="agent_installer_id", - ) - - cmd = XmlCommand("get_agent_installer_file") - cmd.set_attribute("agent_installer_id", str(agent_installer_id)) - - return cmd diff --git a/tests/protocols/gmpnext/entities/agent_installers/__init__.py b/tests/protocols/gmpnext/entities/agent_installer_instructions/__init__.py similarity index 100% rename from tests/protocols/gmpnext/entities/agent_installers/__init__.py rename to tests/protocols/gmpnext/entities/agent_installer_instructions/__init__.py diff --git a/tests/protocols/gmpnext/entities/agent_installer_instructions/test_get_aget_installer_instruction.py b/tests/protocols/gmpnext/entities/agent_installer_instructions/test_get_aget_installer_instruction.py new file mode 100644 index 000000000..fbb4df3ff --- /dev/null +++ b/tests/protocols/gmpnext/entities/agent_installer_instructions/test_get_aget_installer_instruction.py @@ -0,0 +1,57 @@ +# SPDX-FileCopyrightText: 2026 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gvm.errors import RequiredArgument +from gvm.protocols.gmp.requests.next import ( + AgentInstallerInstructionLanguageType, +) + + +class GmpGetAgentInstallerInstructionTestMixin: + def test_get_agent_installer_instruction(self): + self.gmp.get_agent_installer_instruction( + scanner_id="scanner1", + language_type=AgentInstallerInstructionLanguageType.EN, + ) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_agent_installer_instruction_de(self): + self.gmp.get_agent_installer_instruction( + scanner_id="scanner1", + language_type=AgentInstallerInstructionLanguageType.DE, + ) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_agent_installer_instruction_without_scanner_id(self): + with self.assertRaises(RequiredArgument): + self.gmp.get_agent_installer_instruction( + scanner_id=None, + language_type=AgentInstallerInstructionLanguageType.EN, + ) + + with self.assertRaises(RequiredArgument): + self.gmp.get_agent_installer_instruction( + scanner_id="", + language_type=AgentInstallerInstructionLanguageType.EN, + ) + + def test_get_agent_installer_instruction_without_language_type(self): + with self.assertRaises(RequiredArgument): + self.gmp.get_agent_installer_instruction( + scanner_id="scanner1", + language_type=None, + ) + + with self.assertRaises(RequiredArgument): + self.gmp.get_agent_installer_instruction( + scanner_id="scanner1", + language_type="", + ) diff --git a/tests/protocols/gmpnext/entities/agent_installers/test_get_agent_installer.py b/tests/protocols/gmpnext/entities/agent_installers/test_get_agent_installer.py deleted file mode 100644 index b5b5e8ef5..000000000 --- a/tests/protocols/gmpnext/entities/agent_installers/test_get_agent_installer.py +++ /dev/null @@ -1,22 +0,0 @@ -# SPDX-FileCopyrightText: 2018-2024 Greenbone AG -# -# SPDX-License-Identifier: GPL-3.0-or-later -# - -from gvm.errors import RequiredArgument - - -class GmpGetAgentInstallerTestMixin: - def test_get_agent_installer(self): - self.gmp.get_agent_installer(agent_installer_id="installer1") - - self.connection.send.has_been_called_with( - b'' - ) - - def test_get_agent_installer_without_id(self): - with self.assertRaises(RequiredArgument): - self.gmp.get_agent_installer(None) - - with self.assertRaises(RequiredArgument): - self.gmp.get_agent_installer("") diff --git a/tests/protocols/gmpnext/entities/agent_installers/test_get_agent_installer_file.py b/tests/protocols/gmpnext/entities/agent_installers/test_get_agent_installer_file.py deleted file mode 100644 index 2757e3adc..000000000 --- a/tests/protocols/gmpnext/entities/agent_installers/test_get_agent_installer_file.py +++ /dev/null @@ -1,22 +0,0 @@ -# SPDX-FileCopyrightText: 2018-2024 Greenbone AG -# -# SPDX-License-Identifier: GPL-3.0-or-later -# - -from gvm.errors import RequiredArgument - - -class GmpGetAgentInstallerFileTestMixin: - def test_get_agent_installer(self): - self.gmp.get_agent_installer_file(agent_installer_id="installer1") - - self.connection.send.has_been_called_with( - b'' - ) - - def test_get_agent_installer_without_id(self): - with self.assertRaises(RequiredArgument): - self.gmp.get_agent_installer_file(None) - - with self.assertRaises(RequiredArgument): - self.gmp.get_agent_installer_file("") diff --git a/tests/protocols/gmpnext/entities/agent_installers/test_get_agent_installers.py b/tests/protocols/gmpnext/entities/agent_installers/test_get_agent_installers.py deleted file mode 100644 index 819e5121e..000000000 --- a/tests/protocols/gmpnext/entities/agent_installers/test_get_agent_installers.py +++ /dev/null @@ -1,47 +0,0 @@ -# SPDX-FileCopyrightText: 2025 Greenbone AG -# -# SPDX-License-Identifier: GPL-3.0-or-later - - -class GmpGetAgentInstallersTestMixin: - def test_get_agent_installers(self): - self.gmp.get_agent_installers() - - self.connection.send.has_been_called_with(b"") - - def test_get_agent_installers_trash(self): - self.gmp.get_agent_installers(trash=True) - - self.connection.send.has_been_called_with( - b'' - ) - - def test_get_agent_installers_with_filter_string(self): - self.gmp.get_agent_installers( - filter_string="name=foo", - ) - - self.connection.send.has_been_called_with( - b'' - ) - - def test_get_agent_installers_with_filter_id(self): - self.gmp.get_agent_installers(filter_id="f1") - - self.connection.send.has_been_called_with( - b'' - ) - - def test_get_agent_installers_with_details(self): - self.gmp.get_agent_installers(details=True) - - self.connection.send.has_been_called_with( - b'' - ) - - def test_get_agent_installers_without_details(self): - self.gmp.get_agent_installers(details=False) - - self.connection.send.has_been_called_with( - b'' - ) diff --git a/tests/protocols/gmpnext/entities/test_agent_installer_instructions.py b/tests/protocols/gmpnext/entities/test_agent_installer_instructions.py new file mode 100644 index 000000000..47f985cd5 --- /dev/null +++ b/tests/protocols/gmpnext/entities/test_agent_installer_instructions.py @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2023-2026 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpnext import GMPTestCase +from .agent_installer_instructions.test_get_aget_installer_instruction import ( + GmpGetAgentInstallerInstructionTestMixin, +) + + +class GMPGetAgentInstallerInstructionTestCase( + GmpGetAgentInstallerInstructionTestMixin, GMPTestCase +): + pass diff --git a/tests/protocols/gmpnext/entities/test_agent_installers.py b/tests/protocols/gmpnext/entities/test_agent_installers.py deleted file mode 100644 index 08170e2c4..000000000 --- a/tests/protocols/gmpnext/entities/test_agent_installers.py +++ /dev/null @@ -1,31 +0,0 @@ -# SPDX-FileCopyrightText: 2023-2025 Greenbone AG -# -# SPDX-License-Identifier: GPL-3.0-or-later -# - -from ...gmpnext import GMPTestCase -from .agent_installers.test_get_agent_installer import ( - GmpGetAgentInstallerTestMixin, -) -from .agent_installers.test_get_agent_installer_file import ( - GmpGetAgentInstallerFileTestMixin, -) -from .agent_installers.test_get_agent_installers import ( - GmpGetAgentInstallersTestMixin, -) - - -class GMPGetAgentInstallerTestCase(GmpGetAgentInstallerTestMixin, GMPTestCase): - pass - - -class GMPGetAgentInstallerFileTestCase( - GmpGetAgentInstallerFileTestMixin, GMPTestCase -): - pass - - -class GMPGetAgentInstallersTestCase( - GmpGetAgentInstallersTestMixin, GMPTestCase -): - pass