Skip to content

Commit ead1ca1

Browse files
ozgengreenbonebot
authored andcommitted
add: add get_scan_report request support
1 parent 727ce1b commit ead1ca1

6 files changed

Lines changed: 147 additions & 0 deletions

File tree

gvm/protocols/gmp/_gmpnext.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
ReportPorts,
3131
ReportTlsCertificates,
3232
ReportVulnerabilities,
33+
ScanReports,
3334
Targets,
3435
Tasks,
3536
WebApplicationTargets,
@@ -1642,3 +1643,31 @@ def get_targets(
16421643
tasks=tasks,
16431644
)
16441645
)
1646+
1647+
def get_scan_report(
1648+
self,
1649+
scan_report_id: EntityID,
1650+
*,
1651+
filter_string: str | None = None,
1652+
filter_id: str | None = None,
1653+
) -> T:
1654+
""" "Request a structured summary of a single scan report.
1655+
1656+
Args:
1657+
scan_report_id: UUID of an existing scan report.
1658+
filter_string: Filter term to apply to the report results.
1659+
filter_id: UUID of a saved filter to apply to the report results.
1660+
1661+
Returns:
1662+
A request for the get_scan_report GMP command.
1663+
1664+
Raises:
1665+
RequiredArgument: If scan_report_id is not provided.
1666+
"""
1667+
return self._send_request_and_transform_response(
1668+
ScanReports.get_scan_report(
1669+
scan_report_id=scan_report_id,
1670+
filter_string=filter_string,
1671+
filter_id=filter_id,
1672+
)
1673+
)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from gvm.protocols.gmp.requests.next._report_vulnerabilities import (
4545
ReportVulnerabilities,
4646
)
47+
from gvm.protocols.gmp.requests.next._scan_report import ScanReports
4748
from gvm.protocols.gmp.requests.next._targets import AliveTest, Targets
4849
from gvm.protocols.gmp.requests.next._tasks import Tasks
4950
from gvm.protocols.gmp.requests.next._web_application_targets import (
@@ -184,6 +185,7 @@
184185
"Results",
185186
"Roles",
186187
"ScanConfigs",
188+
"ScanReports",
187189
"ScannerType",
188190
"Scanners",
189191
"Schedules",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from gvm.errors import RequiredArgument
2+
from gvm.protocols.core import Request
3+
from gvm.protocols.gmp.requests import EntityID
4+
from gvm.xml import XmlCommand
5+
6+
7+
class ScanReports:
8+
@classmethod
9+
def get_scan_report(
10+
cls,
11+
scan_report_id: EntityID,
12+
*,
13+
filter_string: str | None = None,
14+
filter_id: str | None = None,
15+
) -> Request:
16+
"""Request a structured summary of a single scan report.
17+
18+
Args:
19+
scan_report_id: UUID of an existing scan report.
20+
filter_string: Filter term to apply to the report results.
21+
filter_id: UUID of a saved filter to apply to the report results.
22+
23+
Returns:
24+
A request for the get_scan_report GMP command.
25+
26+
Raises:
27+
RequiredArgument: If scan_report_id is not provided.
28+
"""
29+
if not scan_report_id:
30+
raise RequiredArgument(
31+
function=cls.get_scan_report.__name__,
32+
argument="scan_report_id",
33+
)
34+
35+
cmd = XmlCommand("get_scan_report")
36+
cmd.set_attribute("scan_report_id", str(scan_report_id))
37+
cmd.add_filter(filter_string, filter_id)
38+
39+
return cmd
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-FileCopyrightText: 2026 Greenbone AG
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
#
5+
6+
from .test_get_scan_report import (
7+
GmpGetScanReportTestMixin,
8+
)
9+
10+
__all__ = ("GmpGetScanReportTestMixin",)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 GmpGetScanReportTestMixin:
10+
def test_get_scan_report_without_id(self):
11+
with self.assertRaises(RequiredArgument):
12+
self.gmp.get_scan_report(None)
13+
14+
with self.assertRaises(RequiredArgument):
15+
self.gmp.get_scan_report("")
16+
17+
def test_get_scan_report_with_id(self):
18+
self.gmp.get_scan_report(scan_report_id="r1")
19+
20+
self.connection.send.has_been_called_with(
21+
b'<get_scan_report scan_report_id="r1"/>'
22+
)
23+
24+
def test_get_scan_report_with_filter_string(self):
25+
self.gmp.get_scan_report(
26+
scan_report_id="r1",
27+
filter_string="name=foo",
28+
)
29+
30+
self.connection.send.has_been_called_with(
31+
b'<get_scan_report scan_report_id="r1" filter="name=foo"/>'
32+
)
33+
34+
def test_get_scan_report_with_filter_id(self):
35+
self.gmp.get_scan_report(
36+
scan_report_id="r1",
37+
filter_id="f1",
38+
)
39+
40+
self.connection.send.has_been_called_with(
41+
b'<get_scan_report scan_report_id="r1" filt_id="f1"/>'
42+
)
43+
44+
def test_get_scan_report_with_filter_string_and_filter_id(self):
45+
self.gmp.get_scan_report(
46+
scan_report_id="r1",
47+
filter_string="name=foo",
48+
filter_id="f1",
49+
)
50+
51+
self.connection.send.has_been_called_with(
52+
b'<get_scan_report scan_report_id="r1" '
53+
b'filter="name=foo" filt_id="f1"/>'
54+
)
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 .scan_reports.test_get_scan_report import (
8+
GmpGetScanReportTestMixin,
9+
)
10+
11+
12+
class GmpGetScanReportTestCase(GmpGetScanReportTestMixin, GMPTestCase):
13+
pass

0 commit comments

Comments
 (0)