Skip to content

Commit b145895

Browse files
ozgengreenbonebot
authored andcommitted
add: add get_report_tls_certificates GMP request
Implement the get_report_tls_certificates GMP request command. Add unit tests to verify required arguments, filters, pagination handling, and details output.
1 parent 000834d commit b145895

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
@@ -24,6 +24,7 @@
2424
ReportHosts,
2525
ReportOperatingSystems,
2626
ReportPorts,
27+
ReportTlsCertificates,
2728
Tasks,
2829
)
2930
from .requests.v224 import HostsOrdering
@@ -1088,6 +1089,36 @@ def get_report_ports(
10881089
)
10891090
)
10901091

1092+
def get_report_tls_certificates(
1093+
self,
1094+
report_id: EntityID,
1095+
*,
1096+
filter_string: str | None = None,
1097+
filter_id: str | None = None,
1098+
ignore_pagination: bool | None = None,
1099+
details: bool | None = True,
1100+
) -> T:
1101+
"""Request TLS certificates of a single report.
1102+
1103+
Args:
1104+
report_id: UUID of an existing report.
1105+
filter_string: Filter term to use to filter results in the report
1106+
filter_id: UUID of filter to use to filter results in the report
1107+
ignore_pagination: Whether to ignore the filter terms "first" and
1108+
"rows".
1109+
details: Request additional report TLS certificate information details.
1110+
Defaults to True.
1111+
"""
1112+
return self._send_request_and_transform_response(
1113+
ReportTlsCertificates.get_report_tls_certificates(
1114+
report_id=report_id,
1115+
filter_string=filter_string,
1116+
filter_id=filter_id,
1117+
ignore_pagination=ignore_pagination,
1118+
details=details,
1119+
)
1120+
)
1121+
10911122
def get_report_applications(
10921123
self,
10931124
report_id: EntityID,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
from gvm.protocols.gmp.requests.next._report_ports import (
3030
ReportPorts,
3131
)
32+
from gvm.protocols.gmp.requests.next._report_tls_certificates import (
33+
ReportTlsCertificates,
34+
)
3235
from gvm.protocols.gmp.requests.next._tasks import Tasks
3336

3437
from .._entity_id import EntityID
@@ -156,6 +159,7 @@
156159
"ReportHosts",
157160
"ReportOperatingSystems",
158161
"ReportPorts",
162+
"ReportTlsCertificates",
159163
"Reports",
160164
"ResourceNames",
161165
"ResourceType",
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 ReportTlsCertificates:
9+
@classmethod
10+
def get_report_tls_certificates(
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 TLS certificates 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 TLS certificate information details.
28+
Defaults to True.
29+
"""
30+
cmd = XmlCommand("get_report_tls_certificates")
31+
32+
if not report_id:
33+
raise RequiredArgument(
34+
function=cls.get_report_tls_certificates.__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 GmpGetReportTlsCertificatesTestMixin:
10+
def test_get_report_tls_certificates_without_id(self):
11+
with self.assertRaises(RequiredArgument):
12+
self.gmp.get_report_tls_certificates(None)
13+
14+
with self.assertRaises(RequiredArgument):
15+
self.gmp.get_report_tls_certificates("")
16+
17+
def test_get_report_tls_certificates_with_filter_string(self):
18+
self.gmp.get_report_tls_certificates(
19+
report_id="r1", filter_string="name=foo"
20+
)
21+
22+
self.connection.send.has_been_called_with(
23+
b'<get_report_tls_certificates report_id="r1" filter="name=foo" details="1"/>'
24+
)
25+
26+
def test_get_report_tls_certificates_with_filter_id(self):
27+
self.gmp.get_report_tls_certificates(report_id="r1", filter_id="f1")
28+
29+
self.connection.send.has_been_called_with(
30+
b'<get_report_tls_certificates report_id="r1" filt_id="f1" details="1"/>'
31+
)
32+
33+
def test_get_report_tls_certificates_with_ignore_pagination(self):
34+
self.gmp.get_report_tls_certificates(
35+
report_id="r1", ignore_pagination=True
36+
)
37+
38+
self.connection.send.has_been_called_with(
39+
b'<get_report_tls_certificates report_id="r1" ignore_pagination="1" details="1"/>'
40+
)
41+
42+
self.gmp.get_report_tls_certificates(
43+
report_id="r1", ignore_pagination=False
44+
)
45+
46+
self.connection.send.has_been_called_with(
47+
b'<get_report_tls_certificates report_id="r1" ignore_pagination="0" details="1"/>'
48+
)
49+
50+
def test_get_report_tls_certificates_with_details(self):
51+
self.gmp.get_report_tls_certificates(report_id="r1", details=True)
52+
53+
self.connection.send.has_been_called_with(
54+
b'<get_report_tls_certificates report_id="r1" details="1"/>'
55+
)
56+
57+
self.gmp.get_report_tls_certificates(report_id="r1", details=False)
58+
59+
self.connection.send.has_been_called_with(
60+
b'<get_report_tls_certificates 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_tls_certificates.test_get_report_tls_certificates import (
8+
GmpGetReportTlsCertificatesTestMixin,
9+
)
10+
11+
12+
class GmpGetReportTlsCertificatesTestCase(
13+
GmpGetReportTlsCertificatesTestMixin, GMPTestCase
14+
):
15+
pass

0 commit comments

Comments
 (0)