Skip to content

Commit 8fd3d4e

Browse files
committed
Implement report config commands
Extend GMP classed to support all report config commands.
1 parent 94ec138 commit 8fd3d4e

File tree

13 files changed

+872
-116
lines changed

13 files changed

+872
-116
lines changed

gvm/protocols/gmp/_gmp.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
#
33
# SPDX-License-Identifier: GPL-3.0-or-later
44

5+
import warnings
56
from types import TracebackType
67
from typing import Callable, Optional, Type, Union
78

9+
from gvm.__version__ import __version__
810
from gvm.connections import GvmConnection
911
from gvm.errors import GvmError
1012
from gvm.protocols.core import Response
@@ -16,6 +18,7 @@
1618
from .requests import Version
1719

1820
SUPPORTED_GMP_VERSIONS = Union[GMPv224[T], GMPv225[T], GMPv226[T]]
21+
_SUPPORTED_GMP_VERSION_STRINGS = ["22.4", "22.5", "22.6"]
1922

2023

2124
class GMP(GvmProtocol[T]):
@@ -91,12 +94,21 @@ def determine_supported_gmp(self) -> SUPPORTED_GMP_VERSIONS:
9194
gmp_class = GMPv224
9295
elif major_version == 22 and minor_version == 5:
9396
gmp_class = GMPv225
94-
elif major_version == 22 and minor_version == 6:
97+
elif major_version == 22 and minor_version >= 6:
9598
gmp_class = GMPv226
99+
if minor_version > 6:
100+
warnings.warn(
101+
"Remote manager daemon uses a newer GMP version then "
102+
f"supported by python-gvm {__version__}. Please update to "
103+
"a newer release of python-gvm if possible. "
104+
f"Remote GMP version is {major_version}.{minor_version}. "
105+
f"Supported GMP versions are {', '.join(_SUPPORTED_GMP_VERSION_STRINGS)}."
106+
)
96107
else:
97108
raise GvmError(
98109
"Remote manager daemon uses an unsupported version of GMP. "
99110
f"The GMP version was {major_version}.{minor_version}"
111+
f"Supported GMP versions are {', '.join(_SUPPORTED_GMP_VERSION_STRINGS)}."
100112
)
101113

102114
return gmp_class(self._connection, transform=self._transform_callable) # type: ignore[arg-type]

gvm/protocols/gmp/_gmp226.py

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# SPDX-FileCopyrightText: 2024 Greenbone AG
1+
# SPDX-FileCopyrightText: 2025 Greenbone AG
22
#
33
# SPDX-License-Identifier: GPL-3.0-or-later
44

55
"""
66
Greenbone Management Protocol (GMP) version 22.6
77
"""
88

9-
from typing import Optional, Union
9+
from typing import Optional, Sequence, Union
1010

1111
from .._protocol import T
1212
from ._gmp225 import GMPv225
@@ -15,6 +15,8 @@
1515
EntityID,
1616
Filters,
1717
FilterType,
18+
ReportConfigParameter,
19+
ReportConfigs,
1820
ReportFormatType,
1921
Reports,
2022
ResourceNames,
@@ -334,3 +336,113 @@ def modify_filter(
334336
filter_type=filter_type,
335337
)
336338
)
339+
340+
def clone_report_config(self, report_config_id: EntityID) -> T:
341+
"""Clone a report config from an existing one
342+
343+
Args:
344+
report_config_id: UUID of the existing report config
345+
"""
346+
return self._send_and_transform_command(
347+
ReportConfigs.clone_report_config(report_config_id)
348+
)
349+
350+
def delete_report_config(
351+
self,
352+
report_config_id: EntityID,
353+
*,
354+
ultimate: Optional[bool] = False,
355+
) -> T:
356+
"""Deletes an existing report config
357+
358+
Args:
359+
report_config_id: UUID of the report config to be deleted.
360+
ultimate: Whether to remove entirely, or to the trashcan.
361+
"""
362+
return self._send_and_transform_command(
363+
ReportConfigs.delete_report_config(
364+
report_config_id, ultimate=ultimate
365+
)
366+
)
367+
368+
def get_report_configs(
369+
self,
370+
*,
371+
filter_string: Optional[str] = None,
372+
filter_id: Optional[EntityID] = None,
373+
trash: Optional[bool] = None,
374+
details: Optional[bool] = None,
375+
) -> T:
376+
"""Request a list of report configs
377+
378+
Args:
379+
filter_string: Filter term to use for the query
380+
filter_id: UUID of an existing filter to use for the query
381+
trash: Whether to get the trashcan report configs instead
382+
details: Include report config details
383+
"""
384+
return self._send_and_transform_command(
385+
ReportConfigs.get_report_configs(
386+
filter_string=filter_string,
387+
filter_id=filter_id,
388+
trash=trash,
389+
details=details,
390+
)
391+
)
392+
393+
def get_report_config(
394+
self,
395+
report_config_id: EntityID,
396+
) -> T:
397+
"""Request a single report config
398+
399+
Args:
400+
report_config_id: UUID of an existing report config
401+
"""
402+
return self._send_and_transform_command(
403+
ReportConfigs.get_report_config(report_config_id)
404+
)
405+
406+
def create_report_config(
407+
self,
408+
name: str,
409+
report_format_id: Union[EntityID, ReportFormatType],
410+
*,
411+
comment: Optional[str] = None,
412+
params: Optional[Sequence[ReportConfigParameter]] = None,
413+
) -> T:
414+
"""Create a report config
415+
416+
Args:
417+
name: Name of the new report config
418+
report_format_id: UUID of the report format to be used or ReportFormatType.
419+
comment: An optional comment for the report config.
420+
params: A list of report config parameters.
421+
"""
422+
return self._send_and_transform_command(
423+
ReportConfigs.create_report_config(
424+
name, report_format_id, comment=comment, params=params
425+
)
426+
)
427+
428+
def modify_report_config(
429+
self,
430+
report_config_id: EntityID,
431+
*,
432+
name: Optional[str] = None,
433+
comment: Optional[str] = None,
434+
params: Optional[Sequence[ReportConfigParameter]] = None,
435+
) -> T:
436+
"""Create a report config
437+
438+
Args:
439+
name: Name of the report config
440+
report_config_id: UUID of the report config to be modified.
441+
comment: An optional comment for the report config.
442+
params: A list of report config parameters.
443+
"""
444+
return self._send_and_transform_command(
445+
ReportConfigs.modify_report_config(
446+
report_config_id, name=name, comment=comment, params=params
447+
)
448+
)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
)
7272
from ._audit_reports import AuditReports
7373
from ._filters import Filters, FilterType
74+
from ._report_configs import ReportConfigParameter, ReportConfigs
7475
from ._reports import Reports
7576
from ._resource_names import ResourceNames, ResourceType
7677

@@ -113,6 +114,8 @@
113114
"Policies",
114115
"PortLists",
115116
"PortRangeType",
117+
"ReportConfigs",
118+
"ReportConfigParameter",
116119
"ReportFormatType",
117120
"ReportFormats",
118121
"Reports",

0 commit comments

Comments
 (0)