Skip to content

Commit

Permalink
Implement report config commands
Browse files Browse the repository at this point in the history
Extend GMP classed to support all report config commands.
  • Loading branch information
bjoernricks committed Jan 28, 2025
1 parent 2ccae4d commit c498528
Show file tree
Hide file tree
Showing 12 changed files with 867 additions and 115 deletions.
116 changes: 114 additions & 2 deletions gvm/protocols/gmp/_gmp226.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# SPDX-FileCopyrightText: 2024 Greenbone AG
# SPDX-FileCopyrightText: 2025 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later

"""
Greenbone Management Protocol (GMP) version 22.6
"""

from typing import Optional, Union
from typing import Optional, Sequence, Union

from .._protocol import T
from ._gmp225 import GMPv225
Expand All @@ -15,6 +15,8 @@
EntityID,
Filters,
FilterType,
ReportConfigParameter,
ReportConfigs,
ReportFormatType,
Reports,
ResourceNames,
Expand Down Expand Up @@ -334,3 +336,113 @@ def modify_filter(
filter_type=filter_type,
)
)

def clone_report_config(self, report_config_id: EntityID) -> T:
"""Clone a report config from an existing one
Args:
report_config_id: UUID of the existing report config
"""
return self._send_and_transform_command(
ReportConfigs.clone_report_config(report_config_id)
)

def delete_report_config(
self,
report_config_id: EntityID,
*,
ultimate: Optional[bool] = False,
) -> T:
"""Deletes an existing report config
Args:
report_config_id: UUID of the report config to be deleted.
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_and_transform_command(
ReportConfigs.delete_report_config(
report_config_id, ultimate=ultimate
)
)

def get_report_configs(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of report configs
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get the trashcan report configs instead
details: Include report config details
"""
return self._send_and_transform_command(
ReportConfigs.get_report_configs(
filter_string=filter_string,
filter_id=filter_id,
trash=trash,
details=details,
)
)

def get_report_config(
self,
report_config_id: EntityID,
) -> T:
"""Request a single report config
Args:
report_config_id: UUID of an existing report config
"""
return self._send_and_transform_command(
ReportConfigs.get_report_config(report_config_id)
)

def create_report_config(
self,
name: str,
report_format_id: Union[EntityID, ReportFormatType],
*,
comment: Optional[str] = None,
params: Optional[Sequence[ReportConfigParameter]] = None,
) -> T:
"""Create a report config
Args:
name: Name of the new report config
report_format_id: UUID of the report format to be used or ReportFormatType.
comment: An optional comment for the report config.
params: A list of report config parameters.
"""
return self._send_and_transform_command(
ReportConfigs.create_report_config(
name, report_format_id, comment=comment, params=params
)
)

def modify_report_config(
self,
report_config_id: EntityID,
*,
name: Optional[str] = None,
comment: Optional[str] = None,
params: Optional[Sequence[ReportConfigParameter]] = None,
) -> T:
"""Create a report config
Args:
name: Name of the report config
report_config_id: UUID of the report config to be modified.
comment: An optional comment for the report config.
params: A list of report config parameters.
"""
return self._send_and_transform_command(
ReportConfigs.modify_report_config(
report_config_id, name=name, comment=comment, params=params
)
)
3 changes: 3 additions & 0 deletions gvm/protocols/gmp/requests/v226/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
)
from ._audit_reports import AuditReports
from ._filters import Filters, FilterType
from ._report_configs import ReportConfigParameter, ReportConfigs
from ._reports import Reports
from ._resource_names import ResourceNames, ResourceType

Expand Down Expand Up @@ -113,6 +114,8 @@
"Policies",
"PortLists",
"PortRangeType",
"ReportConfigs",
"ReportConfigParameter",
"ReportFormatType",
"ReportFormats",
"Reports",
Expand Down
Loading

0 comments on commit c498528

Please sign in to comment.