Skip to content

Commit 01a1f26

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

4 files changed

Lines changed: 141 additions & 0 deletions

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+
ReportApplications,
2223
ReportHosts,
2324
ReportPorts,
2425
Tasks,
@@ -1054,3 +1055,33 @@ def get_report_ports(
10541055
details=details,
10551056
)
10561057
)
1058+
1059+
def get_report_applications(
1060+
self,
1061+
report_id: EntityID,
1062+
*,
1063+
filter_string: str | None = None,
1064+
filter_id: str | None = None,
1065+
ignore_pagination: bool | None = None,
1066+
details: bool | None = True,
1067+
) -> T:
1068+
"""Request applications of a single report.
1069+
1070+
Args:
1071+
report_id: UUID of an existing report.
1072+
filter_string: Filter term to use to filter results in the report
1073+
filter_id: UUID of filter to use to filter results in the report
1074+
ignore_pagination: Whether to ignore the filter terms "first" and
1075+
"rows".
1076+
details: Request additional report application information details.
1077+
Defaults to True.
1078+
"""
1079+
return self._send_request_and_transform_response(
1080+
ReportApplications.get_report_applications(
1081+
report_id=report_id,
1082+
filter_string=filter_string,
1083+
filter_id=filter_id,
1084+
ignore_pagination=ignore_pagination,
1085+
details=details,
1086+
)
1087+
)

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_applications import (
18+
ReportApplications,
19+
)
1720
from gvm.protocols.gmp.requests.next._report_hosts import (
1821
ReportHosts,
1922
)
@@ -138,6 +141,7 @@
138141
"Policies",
139142
"PortLists",
140143
"PortRangeType",
144+
"ReportApplications",
141145
"ReportConfigParameter",
142146
"ReportConfigs",
143147
"ReportFormatType",
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 ReportApplications:
9+
@classmethod
10+
def get_report_applications(
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 applications 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 applications information details.
28+
Defaults to True.
29+
"""
30+
cmd = XmlCommand("get_report_applications")
31+
32+
if not report_id:
33+
raise RequiredArgument(
34+
function=cls.get_report_applications.__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: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 GmpGetReportApplicationsTestMixin:
10+
def test_get_report_applications_without_id(self):
11+
with self.assertRaises(RequiredArgument):
12+
self.gmp.get_report_applications(None)
13+
14+
with self.assertRaises(RequiredArgument):
15+
self.gmp.get_report_applications("")
16+
17+
def test_get_report_applications_with_filter_string(self):
18+
self.gmp.get_report_applications(
19+
report_id="r1", filter_string="name=foo"
20+
)
21+
22+
self.connection.send.has_been_called_with(
23+
b'<get_report_applications report_id="r1" filter="name=foo" details="1"/>'
24+
)
25+
26+
def test_get_report_applications_with_filter_id(self):
27+
self.gmp.get_report_applications(report_id="r1", filter_id="f1")
28+
29+
self.connection.send.has_been_called_with(
30+
b'<get_report_applications report_id="r1" filt_id="f1" details="1"/>'
31+
)
32+
33+
def test_get_report_applications_with_ignore_pagination(self):
34+
self.gmp.get_report_applications(report_id="r1", ignore_pagination=True)
35+
36+
self.connection.send.has_been_called_with(
37+
b'<get_report_applications report_id="r1" ignore_pagination="1" details="1"/>'
38+
)
39+
40+
self.gmp.get_report_applications(
41+
report_id="r1", ignore_pagination=False
42+
)
43+
44+
self.connection.send.has_been_called_with(
45+
b'<get_report_applications report_id="r1" ignore_pagination="0" details="1"/>'
46+
)
47+
48+
def test_get_report_applications_with_details(self):
49+
self.gmp.get_report_applications(report_id="r1", details=True)
50+
51+
self.connection.send.has_been_called_with(
52+
b'<get_report_applications report_id="r1" details="1"/>'
53+
)
54+
55+
self.gmp.get_report_applications(report_id="r1", details=False)
56+
57+
self.connection.send.has_been_called_with(
58+
b'<get_report_applications report_id="r1" details="0"/>'
59+
)

0 commit comments

Comments
 (0)