Skip to content

Commit 22b65da

Browse files
committed
Add: Support GMP version 22.6
Implement support for GMP version 22.6 which adds audit reports, report configs and changes get feeds.
1 parent 22e1951 commit 22b65da

File tree

96 files changed

+5613
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+5613
-11
lines changed

gvm/protocols/gmp/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from ._gmp import GMP
2020
from ._gmp224 import GMPv224
2121
from ._gmp225 import GMPv225
22+
from ._gmp226 import GMPv226
2223

2324
Gmp = GMP # for backwards compatibility
2425

@@ -27,4 +28,5 @@
2728
"Gmp",
2829
"GMPv224",
2930
"GMPv225",
31+
"GMPv226",
3032
)

gvm/protocols/gmp/_gmp.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
from .._protocol import GvmProtocol, T, str_transform
1313
from ._gmp224 import GMPv224
1414
from ._gmp225 import GMPv225
15+
from ._gmp226 import GMPv226
1516
from .requests import Version
1617

17-
SUPPORTED_GMP_VERSIONS = Union[GMPv224[T], GMPv225[T]]
18+
SUPPORTED_GMP_VERSIONS = Union[GMPv224[T], GMPv225[T], GMPv226[T]]
1819

1920

2021
class GMP(GvmProtocol[T]):
@@ -30,9 +31,11 @@ class GMP(GvmProtocol[T]):
3031
from gvm.protocols.gmp import GMP
3132
3233
with GMP(connection) as gmp:
33-
# gmp can be an instance of gvm.protocols.gmp.GMPv224 or
34-
# gvm.protocols.gmp.GMPv225 depending
35-
# on the supported GMP version of the remote manager daemon
34+
# gmp can be an instance of
35+
# gvm.protocols.gmp.GMPv224,
36+
# gvm.protocols.gmp.GMPv225
37+
# or gvm.protocols.gmp.GMPv226
38+
# depending on the supported GMP version of the remote manager daemon
3639
resp = gmp.get_tasks()
3740
3841
"""
@@ -88,6 +91,8 @@ def determine_supported_gmp(self) -> SUPPORTED_GMP_VERSIONS:
8891
gmp_class = GMPv224
8992
elif major_version == 22 and minor_version == 5:
9093
gmp_class = GMPv225
94+
elif major_version == 22 and minor_version == 6:
95+
gmp_class = GMPv226
9196
else:
9297
raise GvmError(
9398
"Remote manager daemon uses an unsupported version of GMP. "

gvm/protocols/gmp/_gmp226.py

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
# SPDX-FileCopyrightText: 2024 Greenbone AG
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
"""
6+
Greenbone Management Protocol (GMP) version 22.6
7+
"""
8+
9+
from typing import Optional, Union
10+
11+
from .._protocol import T
12+
from ._gmp225 import GMPv225
13+
from .requests.v226 import (
14+
AuditReports,
15+
EntityID,
16+
ReportFormatType,
17+
Reports,
18+
ResourceNames,
19+
ResourceType,
20+
)
21+
22+
23+
class GMPv226(GMPv225[T]):
24+
"""
25+
A class implementing the Greenbone Management Protocol (GMP) version 22.6
26+
27+
Example:
28+
29+
.. code-block:: python
30+
31+
from gvm.protocols.gmp import GMPv226 as GMP
32+
33+
with GMP(connection) as gmp:
34+
resp = gmp.get_tasks()
35+
"""
36+
37+
def __init__(self, *args, **kwargs):
38+
"""
39+
Create a new GMPv226 instance.
40+
41+
Args:
42+
connection: Connection to use to talk with the remote daemon. See
43+
:mod:`gvm.connections` for possible connection types.
44+
transform: Optional transform `callable`_ to convert response data.
45+
After each request the callable gets passed the plain response data
46+
which can be used to check the data and/or conversion into different
47+
representations like a xml dom.
48+
49+
See :mod:`gvm.transforms` for existing transforms.
50+
51+
.. _callable:
52+
https://docs.python.org/3/library/functions.html#callable
53+
"""
54+
super().__init__(*args, **kwargs)
55+
56+
@staticmethod
57+
def get_protocol_version() -> tuple[int, int]:
58+
return (22, 6)
59+
60+
def get_resource_names(
61+
self,
62+
resource_type: ResourceType, # type: ignore[override]
63+
*,
64+
filter_string: Optional[str] = None,
65+
) -> T:
66+
"""Request a list of resource names and IDs
67+
68+
Arguments:
69+
resource_type: Type must be either ALERT, CERT_BUND_ADV,
70+
CONFIG, CPE, CREDENTIAL, CVE, DFN_CERT_ADV, FILTER,
71+
GROUP, HOST, NOTE, NVT, OS, OVERRIDE, PERMISSION,
72+
PORT_LIST, REPORT_FORMAT, REPORT, REPORT_CONFIG, RESULT, ROLE,
73+
SCANNER, SCHEDULE, TARGET, TASK, TLS_CERTIFICATE
74+
or USER
75+
filter_string: Filter term to use for the query
76+
"""
77+
return self._send_and_transform_command(
78+
ResourceNames.get_resource_names(
79+
resource_type, filter_string=filter_string
80+
)
81+
)
82+
83+
def get_resource_name(
84+
self, resource_id: str, resource_type: ResourceType # type: ignore[override]
85+
) -> T:
86+
"""Request a single resource name
87+
88+
Arguments:
89+
resource_id: ID of an existing resource
90+
resource_type: Type must be either ALERT, CERT_BUND_ADV,
91+
CONFIG, CPE, CREDENTIAL, CVE, DFN_CERT_ADV, FILTER,
92+
GROUP, HOST, NOTE, NVT, OS, OVERRIDE, PERMISSION,
93+
PORT_LIST, REPORT_FORMAT, REPORT, REPORT_CONFIG, RESULT, ROLE,
94+
SCANNER, SCHEDULE, TARGET, TASK, TLS_CERTIFICATE
95+
or USER
96+
"""
97+
return self._send_and_transform_command(
98+
ResourceNames.get_resource_name(resource_id, resource_type)
99+
)
100+
101+
def delete_report(self, report_id: EntityID) -> T:
102+
"""Deletes an existing scan report
103+
104+
Args:
105+
report_id: UUID of the report to be deleted.
106+
"""
107+
return self._send_and_transform_command(
108+
Reports.delete_report(report_id)
109+
)
110+
111+
def get_report(
112+
self,
113+
report_id: EntityID,
114+
*,
115+
filter_string: Optional[str] = None,
116+
filter_id: Optional[str] = None,
117+
delta_report_id: Optional[EntityID] = None,
118+
report_format_id: Optional[Union[str, ReportFormatType]] = None,
119+
ignore_pagination: Optional[bool] = None,
120+
details: Optional[bool] = True,
121+
) -> T:
122+
"""Request a single scan report
123+
124+
Args:
125+
report_id: UUID of an existing report
126+
filter_string: Filter term to use to filter results in the report
127+
filter_id: UUID of filter to use to filter results in the report
128+
delta_report_id: UUID of an existing report to compare report to.
129+
report_format_id: UUID of report format to use
130+
or ReportFormatType (enum)
131+
ignore_pagination: Whether to ignore the filter terms "first" and
132+
"rows".
133+
details: Request additional report information details
134+
defaults to True
135+
"""
136+
return self._send_and_transform_command(
137+
Reports.get_report(
138+
report_id,
139+
filter_string=filter_string,
140+
filter_id=filter_id,
141+
delta_report_id=delta_report_id,
142+
report_format_id=report_format_id,
143+
ignore_pagination=ignore_pagination,
144+
details=details,
145+
)
146+
)
147+
148+
def get_reports(
149+
self,
150+
*,
151+
filter_string: Optional[str] = None,
152+
filter_id: Optional[EntityID] = None,
153+
note_details: Optional[bool] = None,
154+
override_details: Optional[bool] = None,
155+
ignore_pagination: Optional[bool] = None,
156+
details: Optional[bool] = None,
157+
) -> T:
158+
"""Request a list of scan reports
159+
160+
Args:
161+
filter_string: Filter term to use for the query
162+
filter_id: UUID of an existing filter to use for the query
163+
note_details: If notes are included, whether to include note details
164+
override_details: If overrides are included, whether to include
165+
override details
166+
ignore_pagination: Whether to ignore the filter terms "first" and
167+
"rows".
168+
details: Whether to exclude results
169+
"""
170+
return self._send_and_transform_command(
171+
Reports.get_reports(
172+
filter_string=filter_string,
173+
filter_id=filter_id,
174+
note_details=note_details,
175+
override_details=override_details,
176+
ignore_pagination=ignore_pagination,
177+
details=details,
178+
)
179+
)
180+
181+
def import_report(
182+
self,
183+
report: str,
184+
task_id: EntityID,
185+
*,
186+
in_assets: Optional[bool] = None,
187+
) -> T:
188+
"""Import a scan Report from XML
189+
190+
Args:
191+
report: Report XML as string to import. This XML must contain
192+
a :code:`<report>` root element.
193+
task_id: UUID of task to import report to
194+
in_asset: Whether to create or update assets using the report
195+
"""
196+
return self._send_and_transform_command(
197+
Reports.import_report(report, task_id, in_assets=in_assets)
198+
)
199+
200+
def delete_audit_report(self, report_id: EntityID) -> T:
201+
"""Deletes an existing audit report
202+
203+
Args:
204+
report_id: UUID of the report to be deleted.
205+
"""
206+
return self._send_and_transform_command(
207+
AuditReports.delete_report(report_id)
208+
)
209+
210+
def get_audit_report(
211+
self,
212+
report_id: EntityID,
213+
*,
214+
filter_string: Optional[str] = None,
215+
filter_id: Optional[str] = None,
216+
delta_report_id: Optional[EntityID] = None,
217+
report_format_id: Optional[Union[str, ReportFormatType]] = None,
218+
ignore_pagination: Optional[bool] = None,
219+
details: Optional[bool] = True,
220+
) -> T:
221+
"""Request a single audit report
222+
223+
Args:
224+
report_id: UUID of an existing audit report
225+
filter_string: Filter term to use to filter results in the report
226+
filter_id: UUID of filter to use to filter results in the report
227+
delta_report_id: UUID of an existing report to compare report to.
228+
report_format_id: UUID of report format to use
229+
or ReportFormatType (enum)
230+
ignore_pagination: Whether to ignore the filter terms "first" and
231+
"rows".
232+
details: Request additional report information details
233+
defaults to True
234+
"""
235+
return self._send_and_transform_command(
236+
AuditReports.get_report(
237+
report_id,
238+
filter_string=filter_string,
239+
filter_id=filter_id,
240+
delta_report_id=delta_report_id,
241+
report_format_id=report_format_id,
242+
ignore_pagination=ignore_pagination,
243+
details=details,
244+
)
245+
)
246+
247+
def get_audit_reports(
248+
self,
249+
*,
250+
filter_string: Optional[str] = None,
251+
filter_id: Optional[EntityID] = None,
252+
note_details: Optional[bool] = None,
253+
override_details: Optional[bool] = None,
254+
ignore_pagination: Optional[bool] = None,
255+
details: Optional[bool] = None,
256+
) -> T:
257+
"""Request a list of audit reports
258+
259+
Args:
260+
filter_string: Filter term to use for the query
261+
filter_id: UUID of an existing filter to use for the query
262+
note_details: If notes are included, whether to include note details
263+
override_details: If overrides are included, whether to include
264+
override details
265+
ignore_pagination: Whether to ignore the filter terms "first" and
266+
"rows".
267+
details: Whether to exclude results
268+
"""
269+
return self._send_and_transform_command(
270+
AuditReports.get_reports(
271+
filter_string=filter_string,
272+
filter_id=filter_id,
273+
note_details=note_details,
274+
override_details=override_details,
275+
ignore_pagination=ignore_pagination,
276+
details=details,
277+
)
278+
)

0 commit comments

Comments
 (0)