Skip to content

Commit b383352

Browse files
committed
add: add get_report_hosts GMP request
Implement the get_report_hosts GMP request command. Add unit tests to verify required arguments, filters, pagination handling, and details output.
1 parent 0d771ba commit b383352

6 files changed

Lines changed: 150 additions & 1 deletion

File tree

gvm/protocols/gmp/_gmpnext.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
CredentialStores,
2020
IntegrationConfigs,
2121
OCIImageTargets,
22+
ReportHosts,
2223
Tasks,
2324
)
2425
from .requests.v224 import HostsOrdering
@@ -992,3 +993,33 @@ def modify_integration_config(
992993
oidc_provider_client_secret=oidc_provider_client_secret,
993994
)
994995
)
996+
997+
def get_report_hosts(
998+
self,
999+
report_id: EntityID,
1000+
*,
1001+
filter_string: str | None = None,
1002+
filter_id: str | None = None,
1003+
ignore_pagination: bool | None = None,
1004+
details: bool | None = True,
1005+
) -> T:
1006+
"""Request hosts of a single report.
1007+
1008+
Args:
1009+
report_id: UUID of an existing report.
1010+
filter_string: Filter term to use to filter results in the report
1011+
filter_id: UUID of filter to use to filter results in the report
1012+
ignore_pagination: Whether to ignore the filter terms "first" and
1013+
"rows".
1014+
details: Request additional report host information details.
1015+
Defaults to True.
1016+
"""
1017+
return self._send_request_and_transform_response(
1018+
ReportHosts.get_report_hosts(
1019+
report_id=report_id,
1020+
filter_string=filter_string,
1021+
filter_id=filter_id,
1022+
ignore_pagination=ignore_pagination,
1023+
details=details,
1024+
)
1025+
)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
IntegrationConfigs,
1515
)
1616
from gvm.protocols.gmp.requests.next._oci_image_targets import OCIImageTargets
17+
from gvm.protocols.gmp.requests.next._report_hosts import (
18+
ReportHosts,
19+
)
1720
from gvm.protocols.gmp.requests.next._tasks import Tasks
1821

1922
from .._entity_id import EntityID
@@ -136,6 +139,7 @@
136139
"ReportConfigs",
137140
"ReportFormatType",
138141
"ReportFormats",
142+
"ReportHosts",
139143
"Reports",
140144
"ResourceNames",
141145
"ResourceType",
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from gvm.errors import RequiredArgument
2+
from gvm.protocols.core import Request
3+
from gvm.protocols.gmp.requests import EntityID
4+
from gvm.utils import to_bool
5+
from gvm.xml import XmlCommand
6+
7+
8+
class ReportHosts:
9+
@classmethod
10+
def get_report_hosts(
11+
cls,
12+
report_id: EntityID,
13+
*,
14+
filter_string: str | None = None,
15+
filter_id: str | None = None,
16+
ignore_pagination: bool | None = None,
17+
details: bool | None = True,
18+
) -> Request:
19+
"""Request hosts of a single report.
20+
21+
Args:
22+
report_id: UUID of an existing report.
23+
filter_string: Filter term to use to filter results in the report
24+
filter_id: UUID of filter to use to filter results in the report
25+
ignore_pagination: Whether to ignore the filter terms "first" and
26+
"rows".
27+
details: Request additional report host information details.
28+
Defaults to True.
29+
"""
30+
cmd = XmlCommand("get_report_hosts")
31+
32+
if not report_id:
33+
raise RequiredArgument(
34+
function=cls.get_report_hosts.__name__, argument="report_id"
35+
)
36+
37+
cmd.set_attribute("report_id", str(report_id))
38+
39+
cmd.add_filter(filter_string, filter_id)
40+
41+
if ignore_pagination is not None:
42+
cmd.set_attribute("ignore_pagination", to_bool(ignore_pagination))
43+
44+
cmd.set_attribute("details", to_bool(details))
45+
46+
return cmd
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
8+
9+
class GmpGetReportHostsTestMixin:
10+
def test_get_report_hosts_without_id(self):
11+
with self.assertRaises(RequiredArgument):
12+
self.gmp.get_report_hosts(None)
13+
14+
with self.assertRaises(RequiredArgument):
15+
self.gmp.get_report_hosts("")
16+
17+
def test_get_report_hosts_with_filter_string(self):
18+
self.gmp.get_report_hosts(report_id="r1", filter_string="name=foo")
19+
20+
self.connection.send.has_been_called_with(
21+
b'<get_report_hosts report_id="r1" filter="name=foo" details="1"/>'
22+
)
23+
24+
def test_get_report_hosts_with_filter_id(self):
25+
self.gmp.get_report_hosts(report_id="r1", filter_id="f1")
26+
27+
self.connection.send.has_been_called_with(
28+
b'<get_report_hosts report_id="r1" filt_id="f1" details="1"/>'
29+
)
30+
31+
def test_get_report_hosts_with_ignore_pagination(self):
32+
self.gmp.get_report_hosts(report_id="r1", ignore_pagination=True)
33+
34+
self.connection.send.has_been_called_with(
35+
b'<get_report_hosts report_id="r1" ignore_pagination="1" details="1"/>'
36+
)
37+
38+
self.gmp.get_report_hosts(report_id="r1", ignore_pagination=False)
39+
40+
self.connection.send.has_been_called_with(
41+
b'<get_report_hosts report_id="r1" ignore_pagination="0" details="1"/>'
42+
)
43+
44+
def test_get_report_hosts_with_details(self):
45+
self.gmp.get_report_hosts(report_id="r1", details=True)
46+
47+
self.connection.send.has_been_called_with(
48+
b'<get_report_hosts report_id="r1" details="1"/>'
49+
)
50+
51+
self.gmp.get_report_hosts(report_id="r1", details=False)
52+
53+
self.connection.send.has_been_called_with(
54+
b'<get_report_hosts report_id="r1" details="0"/>'
55+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-FileCopyrightText: 2026 Greenbone AG
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
#
5+
6+
from ...gmpnext import GMPTestCase
7+
from .report_hosts.test_get_report_hosts import (
8+
GmpGetReportHostsTestMixin,
9+
)
10+
11+
12+
class GmpGetReportHostsTestCase(GmpGetReportHostsTestMixin, GMPTestCase):
13+
pass

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)