Skip to content

Commit

Permalink
Implement report formats for new protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernricks committed May 29, 2024
1 parent 53da2e5 commit 4d4346e
Show file tree
Hide file tree
Showing 4 changed files with 664 additions and 1 deletion.
139 changes: 139 additions & 0 deletions gvm/protocols/gmp/_gmp224.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
Policies,
PortLists,
PortRangeType,
ReportFormats,
ReportFormatType,
Reports,
Results,
Expand Down Expand Up @@ -4079,3 +4080,141 @@ def get_vulnerability(self, vulnerability_id: EntityID) -> T:
return self._send_and_transform_command(
Vulnerabilities.get_vulnerability(vulnerability_id)
)

def clone_report_format(
self, report_format_id: Union[EntityID, ReportFormatType]
) -> T:
"""Clone a report format from an existing one
Args:
report_format_id: UUID of the existing report format
or ReportFormatType (enum)
"""
return self._send_and_transform_command(
ReportFormats.clone_report_format(report_format_id)
)

def delete_report_format(
self,
report_format_id: Union[EntityID, ReportFormatType],
*,
ultimate: Optional[bool] = False,
) -> T:
"""Deletes an existing report format
Args:
report_format_id: UUID of the report format to be deleted.
or ReportFormatType (enum)
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_and_transform_command(
ReportFormats.delete_report_format(
report_format_id, ultimate=ultimate
)
)

def get_report_formats(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
alerts: Optional[bool] = None,
params: Optional[bool] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of report formats
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 formats instead
alerts: Whether to include alerts that use the report format
params: Whether to include report format parameters
details: Include report format file, signature and parameters
"""
return self._send_and_transform_command(
ReportFormats.get_report_formats(
filter_string=filter_string,
filter_id=filter_id,
trash=trash,
alerts=alerts,
params=params,
details=details,
)
)

def get_report_format(
self, report_format_id: Union[EntityID, ReportFormatType]
) -> T:
"""Request a single report format
Args:
report_format_id: UUID of an existing report format
or ReportFormatType (enum)
"""
return self._send_and_transform_command(
ReportFormats.get_report_format(report_format_id)
)

def import_report_format(self, report_format: str) -> T:
"""Import a report format from XML
Args:
report_format: Report format XML as string to import. This XML must
contain a :code:`<get_report_formats_response>` root element.
"""
return self._send_and_transform_command(
ReportFormats.import_report_format(report_format)
)

def modify_report_format(
self,
report_format_id: Union[EntityID, ReportFormatType],
*,
active: Optional[bool] = None,
name: Optional[str] = None,
summary: Optional[str] = None,
param_name: Optional[str] = None,
param_value: Optional[str] = None,
) -> T:
"""Modifies an existing report format.
Args:
report_format_id: UUID of report format to modify
or ReportFormatType (enum)
active: Whether the report format is active.
name: The name of the report format.
summary: A summary of the report format.
param_name: The name of the param.
param_value: The value of the param.
"""
return self._send_and_transform_command(
ReportFormats.modify_report_format(
report_format_id,
active=active,
name=name,
summary=summary,
param_name=param_name,
param_value=param_value,
)
)

def verify_report_format(
self, report_format_id: Union[EntityID, ReportFormatType]
) -> T:
"""Verify an existing report format
Verifies the trust level of an existing report format. It will be
checked whether the signature of the report format currently matches the
report format. This includes the script and files used to generate
reports of this format. It is *not* verified if the report format works
as expected by the user.
Args:
report_format_id: UUID of the report format to be verified
or ReportFormatType (enum)
"""
return self._send_and_transform_command(
ReportFormats.verify_report_format(report_format_id)
)
3 changes: 2 additions & 1 deletion gvm/protocols/gmp/requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from ._permissions import Permissions, PermissionSubjectType
from ._policies import Policies
from ._port_lists import PortLists, PortRangeType
from ._report_formats import ReportFormatType
from ._report_formats import ReportFormats, ReportFormatType
from ._reports import Reports
from ._resource_names import ResourceNames, ResourceType
from ._results import Results
Expand Down Expand Up @@ -92,6 +92,7 @@
"PortLists",
"PortRangeType",
"ReportFormatType",
"ReportFormats",
"Reports",
"ResourceNames",
"ResourceType",
Expand Down
Loading

0 comments on commit 4d4346e

Please sign in to comment.