diff --git a/gvm/protocols/gmp/_gmpnext.py b/gvm/protocols/gmp/_gmpnext.py index 0487354e..114e2df9 100644 --- a/gvm/protocols/gmp/_gmpnext.py +++ b/gvm/protocols/gmp/_gmpnext.py @@ -2012,9 +2012,33 @@ def download_report_export( Returns: A request for the download_report_export GMP command. + + Raises: + RequiredArgument: If report_export_id is not provided. """ return self._send_request_and_transform_response( ReportExports.download_report_export( report_export_id=report_export_id, ) ) + + def cancel_report_export( + self, + report_export_id: EntityID, + ) -> T: + """Request cancellation of a report export. + + Args: + report_export_id: UUID of the report export to cancel. + + Returns: + A request for the cancel_report_export GMP command. + + Raises: + RequiredArgument: If report_export_id is not provided. + """ + return self._send_request_and_transform_response( + ReportExports.cancel_report_export( + report_export_id=report_export_id, + ) + ) diff --git a/gvm/protocols/gmp/requests/next/_audit_report.py b/gvm/protocols/gmp/requests/next/_audit_report.py index 144c5957..907eb485 100644 --- a/gvm/protocols/gmp/requests/next/_audit_report.py +++ b/gvm/protocols/gmp/requests/next/_audit_report.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2026 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later + from gvm.errors import RequiredArgument from gvm.protocols.core import Request from gvm.protocols.gmp.requests import EntityID diff --git a/gvm/protocols/gmp/requests/next/_report_exports.py b/gvm/protocols/gmp/requests/next/_report_exports.py index 248db798..36382078 100644 --- a/gvm/protocols/gmp/requests/next/_report_exports.py +++ b/gvm/protocols/gmp/requests/next/_report_exports.py @@ -83,3 +83,33 @@ def download_report_export( ) return cmd + + @classmethod + def cancel_report_export( + cls, + report_export_id: EntityID, + ) -> Request: + """Request cancellation of a report export. + + Args: + report_export_id: UUID of the report export to cancel. + + Returns: + A request for the cancel_report_export GMP command. + + Raises: + RequiredArgument: If report_export_id is not provided. + """ + if not report_export_id: + raise RequiredArgument( + function=cls.cancel_report_export.__name__, + argument="report_export_id", + ) + + cmd = XmlCommand("cancel_report_export") + cmd.set_attribute( + "report_export_id", + str(report_export_id), + ) + + return cmd diff --git a/tests/protocols/gmpnext/entities/report_exports/__init__.py b/tests/protocols/gmpnext/entities/report_exports/__init__.py index f487a5c5..69006a99 100644 --- a/tests/protocols/gmpnext/entities/report_exports/__init__.py +++ b/tests/protocols/gmpnext/entities/report_exports/__init__.py @@ -2,11 +2,13 @@ # # SPDX-License-Identifier: GPL-3.0-or-later +from .test_cancel_report_export import GmpCancelReportExportTestMixin from .test_download_report_export import GmpDownloadReportExportTestMixin from .test_get_report_export import GmpGetReportExportTestMixin from .test_get_report_exports import GmpGetReportExportsTestMixin __all__ = [ + "GmpCancelReportExportTestMixin", "GmpDownloadReportExportTestMixin", "GmpGetReportExportTestMixin", "GmpGetReportExportsTestMixin", diff --git a/tests/protocols/gmpnext/entities/report_exports/test_cancel_report_export.py b/tests/protocols/gmpnext/entities/report_exports/test_cancel_report_export.py new file mode 100644 index 00000000..edf0958a --- /dev/null +++ b/tests/protocols/gmpnext/entities/report_exports/test_cancel_report_export.py @@ -0,0 +1,21 @@ +# SPDX-FileCopyrightText: 2026 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +from gvm.errors import RequiredArgument + + +class GmpCancelReportExportTestMixin: + def test_cancel_report_export_without_id(self): + with self.assertRaises(RequiredArgument): + self.gmp.cancel_report_export(None) + + with self.assertRaises(RequiredArgument): + self.gmp.cancel_report_export("") + + def test_cancel_report_export_with_id(self): + self.gmp.cancel_report_export(report_export_id="e1") + + self.connection.send.has_been_called_with( + b'' + ) diff --git a/tests/protocols/gmpnext/entities/test_report_exports.py b/tests/protocols/gmpnext/entities/test_report_exports.py index c5848c17..b6f0205e 100644 --- a/tests/protocols/gmpnext/entities/test_report_exports.py +++ b/tests/protocols/gmpnext/entities/test_report_exports.py @@ -5,6 +5,7 @@ from ...gmpnext import GMPTestCase from .report_exports import ( + GmpCancelReportExportTestMixin, GmpDownloadReportExportTestMixin, GmpGetReportExportsTestMixin, GmpGetReportExportTestMixin, @@ -23,3 +24,9 @@ class GmpGmpDownloadReportExportTestCase( GmpDownloadReportExportTestMixin, GMPTestCase ): pass + + +class GmpCancelReportExportTestCase( + GmpCancelReportExportTestMixin, GMPTestCase +): + pass