Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions gvm/protocols/gmp/_gmpnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
IntegrationConfigs,
OCIImageTargets,
ReportHosts,
ReportPorts,
Tasks,
)
from .requests.v224 import HostsOrdering
Expand Down Expand Up @@ -1023,3 +1024,33 @@ def get_report_hosts(
details=details,
)
)

def get_report_ports(
self,
report_id: EntityID,
*,
filter_string: str | None = None,
filter_id: str | None = None,
ignore_pagination: bool | None = None,
details: bool | None = True,
) -> T:
"""Request ports of a single report.

Args:
report_id: UUID of an existing report.
filter_string: Filter term to use to filter results in the report
filter_id: UUID of filter to use to filter results in the report
ignore_pagination: Whether to ignore the filter terms "first" and
"rows".
details: Request additional report port information details.
Defaults to True.
"""
return self._send_request_and_transform_response(
ReportPorts.get_report_ports(
report_id=report_id,
filter_string=filter_string,
filter_id=filter_id,
ignore_pagination=ignore_pagination,
details=details,
)
)
4 changes: 4 additions & 0 deletions gvm/protocols/gmp/requests/next/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from gvm.protocols.gmp.requests.next._report_hosts import (
ReportHosts,
)
from gvm.protocols.gmp.requests.next._report_ports import (
ReportPorts,
)
from gvm.protocols.gmp.requests.next._tasks import Tasks

from .._entity_id import EntityID
Expand Down Expand Up @@ -140,6 +143,7 @@
"ReportFormatType",
"ReportFormats",
"ReportHosts",
"ReportPorts",
"Reports",
"ResourceNames",
"ResourceType",
Expand Down
46 changes: 46 additions & 0 deletions gvm/protocols/gmp/requests/next/_report_ports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from gvm.errors import RequiredArgument
from gvm.protocols.core import Request
from gvm.protocols.gmp.requests import EntityID
from gvm.utils import to_bool
from gvm.xml import XmlCommand


class ReportPorts:
@classmethod
def get_report_ports(
cls,
report_id: EntityID,
*,
filter_string: str | None = None,
filter_id: str | None = None,
ignore_pagination: bool | None = None,
details: bool | None = True,
) -> Request:
"""Request ports of a single report.

Args:
report_id: UUID of an existing report.
filter_string: Filter term to use to filter results in the report
filter_id: UUID of filter to use to filter results in the report
ignore_pagination: Whether to ignore the filter terms "first" and
"rows".
details: Request additional report port information details.
Defaults to True.
"""
cmd = XmlCommand("get_report_ports")

if not report_id:
raise RequiredArgument(
function=cls.get_report_ports.__name__, argument="report_id"
)

cmd.set_attribute("report_id", str(report_id))

cmd.add_filter(filter_string, filter_id)

if ignore_pagination is not None:
cmd.set_attribute("ignore_pagination", to_bool(ignore_pagination))

cmd.set_attribute("details", to_bool(details))

return cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# SPDX-FileCopyrightText: 2026 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

from gvm.errors import RequiredArgument


class GmpGetReportPortsTestMixin:
def test_get_report_ports_without_id(self):
with self.assertRaises(RequiredArgument):
self.gmp.get_report_ports(None)

with self.assertRaises(RequiredArgument):
self.gmp.get_report_ports("")

def test_get_report_ports_with_filter_string(self):
self.gmp.get_report_ports(report_id="r1", filter_string="name=foo")

self.connection.send.has_been_called_with(
b'<get_report_ports report_id="r1" filter="name=foo" details="1"/>'
)

def test_get_report_ports_with_filter_id(self):
self.gmp.get_report_ports(report_id="r1", filter_id="f1")

self.connection.send.has_been_called_with(
b'<get_report_ports report_id="r1" filt_id="f1" details="1"/>'
)

def test_get_report_ports_with_ignore_pagination(self):
self.gmp.get_report_ports(report_id="r1", ignore_pagination=True)

self.connection.send.has_been_called_with(
b'<get_report_ports report_id="r1" ignore_pagination="1" details="1"/>'
)

self.gmp.get_report_ports(report_id="r1", ignore_pagination=False)

self.connection.send.has_been_called_with(
b'<get_report_ports report_id="r1" ignore_pagination="0" details="1"/>'
)

def test_get_report_ports_with_details(self):
self.gmp.get_report_ports(report_id="r1", details=True)

self.connection.send.has_been_called_with(
b'<get_report_ports report_id="r1" details="1"/>'
)

self.gmp.get_report_ports(report_id="r1", details=False)

self.connection.send.has_been_called_with(
b'<get_report_ports report_id="r1" details="0"/>'
)
13 changes: 13 additions & 0 deletions tests/protocols/gmpnext/entities/test_report_ports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2026 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

from ...gmpnext import GMPTestCase
from .report_ports.test_get_report_ports import (
GmpGetReportPortsTestMixin,
)


class GmpGetReportPortsTestCase(GmpGetReportPortsTestMixin, GMPTestCase):
pass
Loading