Skip to content

Commit 45028bf

Browse files
committed
add: add get_report_operating_systems GMP request
Implement the get_report_operating_systems GMP request command. Add unit tests to verify required arguments, filters, pagination handling, and details output.
1 parent 06e308b commit 45028bf

5 files changed

Lines changed: 158 additions & 0 deletions

File tree

gvm/protocols/gmp/_gmpnext.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
IntegrationConfigs,
2121
OCIImageTargets,
2222
ReportHosts,
23+
ReportOperatingSystems,
2324
ReportPorts,
2425
Tasks,
2526
)
@@ -1025,6 +1026,36 @@ def get_report_hosts(
10251026
)
10261027
)
10271028

1029+
def get_report_operating_systems(
1030+
self,
1031+
report_id: EntityID,
1032+
*,
1033+
filter_string: str | None = None,
1034+
filter_id: str | None = None,
1035+
ignore_pagination: bool | None = None,
1036+
details: bool | None = True,
1037+
) -> T:
1038+
"""Request operating systems of a single report.
1039+
1040+
Args:
1041+
report_id: UUID of an existing report.
1042+
filter_string: Filter term to use to filter results in the report
1043+
filter_id: UUID of filter to use to filter results in the report
1044+
ignore_pagination: Whether to ignore the filter terms "first" and
1045+
"rows".
1046+
details: Request additional report operating system information details.
1047+
Defaults to True.
1048+
"""
1049+
return self._send_request_and_transform_response(
1050+
ReportOperatingSystems.get_report_operating_systems(
1051+
report_id=report_id,
1052+
filter_string=filter_string,
1053+
filter_id=filter_id,
1054+
ignore_pagination=ignore_pagination,
1055+
details=details,
1056+
)
1057+
)
1058+
10281059
def get_report_ports(
10291060
self,
10301061
report_id: EntityID,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
from gvm.protocols.gmp.requests.next._report_hosts import (
1818
ReportHosts,
1919
)
20+
from gvm.protocols.gmp.requests.next._report_operating_systems import (
21+
ReportOperatingSystems,
22+
)
2023
from gvm.protocols.gmp.requests.next._report_ports import (
2124
ReportPorts,
2225
)
@@ -143,6 +146,7 @@
143146
"ReportFormatType",
144147
"ReportFormats",
145148
"ReportHosts",
149+
"ReportOperatingSystems",
146150
"ReportPorts",
147151
"Reports",
148152
"ResourceNames",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 ReportOperatingSystems:
9+
@classmethod
10+
def get_report_operating_systems(
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 operating systems 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 operating systems information details.
28+
Defaults to True.
29+
"""
30+
cmd = XmlCommand("get_report_operating_systems")
31+
32+
if not report_id:
33+
raise RequiredArgument(
34+
function=cls.get_report_operating_systems.__name__,
35+
argument="report_id",
36+
)
37+
38+
cmd.set_attribute("report_id", str(report_id))
39+
40+
cmd.add_filter(filter_string, filter_id)
41+
42+
if ignore_pagination is not None:
43+
cmd.set_attribute("ignore_pagination", to_bool(ignore_pagination))
44+
45+
cmd.set_attribute("details", to_bool(details))
46+
47+
return cmd
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 GmpGetReportOperatingSystemsTestMixin:
10+
def test_get_report_operating_systems_without_id(self):
11+
with self.assertRaises(RequiredArgument):
12+
self.gmp.get_report_operating_systems(None)
13+
14+
with self.assertRaises(RequiredArgument):
15+
self.gmp.get_report_operating_systems("")
16+
17+
def test_get_report_operating_systems_with_filter_string(self):
18+
self.gmp.get_report_operating_systems(
19+
report_id="r1", filter_string="name=foo"
20+
)
21+
22+
self.connection.send.has_been_called_with(
23+
b'<get_report_operating_systems report_id="r1" filter="name=foo" details="1"/>'
24+
)
25+
26+
def test_get_report_operating_systems_with_filter_id(self):
27+
self.gmp.get_report_operating_systems(report_id="r1", filter_id="f1")
28+
29+
self.connection.send.has_been_called_with(
30+
b'<get_report_operating_systems report_id="r1" filt_id="f1" details="1"/>'
31+
)
32+
33+
def test_get_report_operating_systems_with_ignore_pagination(self):
34+
self.gmp.get_report_operating_systems(
35+
report_id="r1", ignore_pagination=True
36+
)
37+
38+
self.connection.send.has_been_called_with(
39+
b'<get_report_operating_systems report_id="r1" ignore_pagination="1" details="1"/>'
40+
)
41+
42+
self.gmp.get_report_operating_systems(
43+
report_id="r1", ignore_pagination=False
44+
)
45+
46+
self.connection.send.has_been_called_with(
47+
b'<get_report_operating_systems report_id="r1" ignore_pagination="0" details="1"/>'
48+
)
49+
50+
def test_get_report_operating_systems_with_details(self):
51+
self.gmp.get_report_operating_systems(report_id="r1", details=True)
52+
53+
self.connection.send.has_been_called_with(
54+
b'<get_report_operating_systems report_id="r1" details="1"/>'
55+
)
56+
57+
self.gmp.get_report_operating_systems(report_id="r1", details=False)
58+
59+
self.connection.send.has_been_called_with(
60+
b'<get_report_operating_systems report_id="r1" details="0"/>'
61+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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_operating_systems.test_get_report_operating_systems import (
8+
GmpGetReportOperatingSystemsTestMixin,
9+
)
10+
11+
12+
class GmpGetReportOperatingSystemsTestCase(
13+
GmpGetReportOperatingSystemsTestMixin, GMPTestCase
14+
):
15+
pass

0 commit comments

Comments
 (0)