Skip to content

Commit 90f68a3

Browse files
ozgengreenbonebot
authored andcommitted
add: add agent installer instruction GMP request
Add support for the get_agent_installer_instruction GMP request. The request uses a scanner ID and language type to retrieve installer instructions from gvmd. Remove the old agent installer request helpers and tests because installer files are no longer handled by these commands. Add tests for English and German language types and required arguments.
1 parent 8dfcbef commit 90f68a3

11 files changed

Lines changed: 132 additions & 242 deletions

File tree

gvm/protocols/gmp/_gmpnext.py

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from ._gmp227 import GMPv227
1313
from .requests.next import (
1414
AgentGroups,
15-
AgentInstallers,
15+
AgentInstallerInstructionLanguageType,
16+
AgentInstallerInstructions,
1617
Agents,
1718
Credentials,
1819
CredentialStoreCredentialType,
@@ -55,52 +56,25 @@ class GMPNext(GMPv227[T]):
5556
def get_protocol_version() -> tuple[int, int]:
5657
return (22, 8)
5758

58-
def get_agent_installers(
59+
def get_agent_installer_instruction(
5960
self,
6061
*,
61-
filter_string: str | None = None,
62-
filter_id: EntityID | None = None,
63-
trash: bool | None = None,
64-
details: bool | None = None,
62+
scanner_id: EntityID,
63+
language_type: AgentInstallerInstructionLanguageType,
6564
) -> T:
66-
"""Request a list of agent installers
65+
"""Request an agent installer instruction.
6766
6867
Args:
69-
filter_string: Filter term to use for the query
70-
filter_id: UUID of an existing filter to use for the query
71-
trash: Whether to get the trashcan agent installers instead
72-
details: Whether to include extra details like tasks using this
73-
scanner
68+
scanner_id: UUID of the Agent controller to get the installer instruction for.
69+
language_type: Language of the installer instruction.
7470
"""
7571
return self._send_request_and_transform_response(
76-
AgentInstallers.get_agent_installers(
77-
filter_string=filter_string,
78-
filter_id=filter_id,
79-
trash=trash,
80-
details=details,
72+
AgentInstallerInstructions.get_agent_installer_instruction(
73+
scanner_id=scanner_id,
74+
language_type=language_type,
8175
)
8276
)
8377

84-
def get_agent_installer(self, agent_installer_id: EntityID) -> T:
85-
"""Request a single agent installer
86-
87-
Args:
88-
agent_installer_id: UUID of an existing agent installer
89-
"""
90-
return self._send_request_and_transform_response(
91-
AgentInstallers.get_agent_installer(agent_installer_id)
92-
)
93-
94-
def get_agent_installer_file(self, agent_installer_id: EntityID) -> T:
95-
"""Request a single agent installer file
96-
97-
Args:
98-
agent_installer_id: UUID of an existing agent installer
99-
"""
100-
return self._send_request_and_transform_response(
101-
AgentInstallers.get_agent_installer_file(agent_installer_id)
102-
)
103-
10478
def get_agents(
10579
self,
10680
*,

gvm/protocols/gmp/requests/next/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
# SPDX-License-Identifier: GPL-3.0-or-later
44

55
from gvm.protocols.gmp.requests.next._agent_groups import AgentGroups
6-
from gvm.protocols.gmp.requests.next._agent_installers import AgentInstallers
6+
from gvm.protocols.gmp.requests.next._agent_installer_instructions import (
7+
AgentInstallerInstructionLanguageType,
8+
AgentInstallerInstructions,
9+
)
710
from gvm.protocols.gmp.requests.next._agents import Agents
811
from gvm.protocols.gmp.requests.next._credential_stores import CredentialStores
912
from gvm.protocols.gmp.requests.next._credentials import (
@@ -115,7 +118,8 @@
115118

116119
__all__ = (
117120
"AgentGroups",
118-
"AgentInstallers",
121+
"AgentInstallerInstructionLanguageType",
122+
"AgentInstallerInstructions",
119123
"Agents",
120124
"AggregateStatistic",
121125
"Aggregates",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from enum import Enum
2+
3+
from gvm.errors import RequiredArgument
4+
from gvm.protocols.core import Request
5+
from gvm.protocols.gmp.requests._entity_id import EntityID
6+
from gvm.xml import XmlCommand
7+
8+
9+
class AgentInstallerInstructionLanguageType(Enum):
10+
EN = "en"
11+
DE = "de"
12+
13+
14+
class AgentInstallerInstructions:
15+
@classmethod
16+
def get_agent_installer_instruction(
17+
cls,
18+
scanner_id: EntityID,
19+
language_type: AgentInstallerInstructionLanguageType,
20+
) -> Request:
21+
"""Request an agent installer instruction.
22+
23+
Args:
24+
scanner_id: UUID of the Agent controller to get the installer instruction for.
25+
language_type: Language of the installer instruction.
26+
"""
27+
if not scanner_id:
28+
raise RequiredArgument(
29+
function=cls.get_agent_installer_instruction.__name__,
30+
argument="scanner_id",
31+
)
32+
33+
if not language_type:
34+
raise RequiredArgument(
35+
function=cls.get_agent_installer_instruction.__name__,
36+
argument="language_type",
37+
)
38+
39+
cmd = XmlCommand("get_agent_installer_instruction")
40+
cmd.set_attribute("scanner_id", str(scanner_id))
41+
cmd.set_attribute("language", language_type.value)
42+
43+
return cmd

gvm/protocols/gmp/requests/next/_agent_installers.py

Lines changed: 0 additions & 81 deletions
This file was deleted.

tests/protocols/gmpnext/entities/agent_installers/__init__.py renamed to tests/protocols/gmpnext/entities/agent_installer_instructions/__init__.py

File renamed without changes.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# SPDX-FileCopyrightText: 2026 Greenbone AG
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
#
5+
6+
from gvm.errors import RequiredArgument
7+
from gvm.protocols.gmp.requests.next import (
8+
AgentInstallerInstructionLanguageType,
9+
)
10+
11+
12+
class GmpGetAgentInstallerInstructionTestMixin:
13+
def test_get_agent_installer_instruction(self):
14+
self.gmp.get_agent_installer_instruction(
15+
scanner_id="scanner1",
16+
language_type=AgentInstallerInstructionLanguageType.EN,
17+
)
18+
19+
self.connection.send.has_been_called_with(
20+
b'<get_agent_installer_instruction scanner_id="scanner1" language="en"/>'
21+
)
22+
23+
def test_get_agent_installer_instruction_de(self):
24+
self.gmp.get_agent_installer_instruction(
25+
scanner_id="scanner1",
26+
language_type=AgentInstallerInstructionLanguageType.DE,
27+
)
28+
29+
self.connection.send.has_been_called_with(
30+
b'<get_agent_installer_instruction scanner_id="scanner1" language="de"/>'
31+
)
32+
33+
def test_get_agent_installer_instruction_without_scanner_id(self):
34+
with self.assertRaises(RequiredArgument):
35+
self.gmp.get_agent_installer_instruction(
36+
scanner_id=None,
37+
language_type=AgentInstallerInstructionLanguageType.EN,
38+
)
39+
40+
with self.assertRaises(RequiredArgument):
41+
self.gmp.get_agent_installer_instruction(
42+
scanner_id="",
43+
language_type=AgentInstallerInstructionLanguageType.EN,
44+
)
45+
46+
def test_get_agent_installer_instruction_without_language_type(self):
47+
with self.assertRaises(RequiredArgument):
48+
self.gmp.get_agent_installer_instruction(
49+
scanner_id="scanner1",
50+
language_type=None,
51+
)
52+
53+
with self.assertRaises(RequiredArgument):
54+
self.gmp.get_agent_installer_instruction(
55+
scanner_id="scanner1",
56+
language_type="",
57+
)

tests/protocols/gmpnext/entities/agent_installers/test_get_agent_installer.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/protocols/gmpnext/entities/agent_installers/test_get_agent_installer_file.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/protocols/gmpnext/entities/agent_installers/test_get_agent_installers.py

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-FileCopyrightText: 2023-2026 Greenbone AG
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
#
5+
6+
from ...gmpnext import GMPTestCase
7+
from .agent_installer_instructions.test_get_aget_installer_instruction import (
8+
GmpGetAgentInstallerInstructionTestMixin,
9+
)
10+
11+
12+
class GMPGetAgentInstallerInstructionTestCase(
13+
GmpGetAgentInstallerInstructionTestMixin, GMPTestCase
14+
):
15+
pass

0 commit comments

Comments
 (0)