Skip to content

Commit 69da28e

Browse files
ozgenbjoernricks
authored andcommitted
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 df86517 commit 69da28e

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
@@ -21,6 +21,7 @@
2121
OCIImageTargets,
2222
ReportApplications,
2323
ReportHosts,
24+
ReportOperatingSystems,
2425
ReportPorts,
2526
Tasks,
2627
)
@@ -1026,6 +1027,36 @@ def get_report_hosts(
10261027
)
10271028
)
10281029

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

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
from gvm.protocols.gmp.requests.next._report_hosts import (
2121
ReportHosts,
2222
)
23+
from gvm.protocols.gmp.requests.next._report_operating_systems import (
24+
ReportOperatingSystems,
25+
)
2326
from gvm.protocols.gmp.requests.next._report_ports import (
2427
ReportPorts,
2528
)
@@ -147,6 +150,7 @@
147150
"ReportFormatType",
148151
"ReportFormats",
149152
"ReportHosts",
153+
"ReportOperatingSystems",
150154
"ReportPorts",
151155
"Reports",
152156
"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)