Skip to content

Commit

Permalink
Add: Allow to use ignore_pagination for get_tasks
Browse files Browse the repository at this point in the history
GMP has the ignore_pagination attribute for getting a list of tasks. Add
the argument to python-gvm too.

Closes #1138
  • Loading branch information
bjoernricks committed Jun 18, 2024
1 parent 2349792 commit 2bc27a2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gvm/protocols/gmp/_gmp224.py
Original file line number Diff line number Diff line change
Expand Up @@ -3805,6 +3805,7 @@ def get_tasks(
trash: Optional[bool] = None,
details: Optional[bool] = None,
schedules_only: Optional[bool] = None,
ignore_pagination: Optional[bool] = None,
) -> T:
"""Request a list of tasks
Expand All @@ -3815,6 +3816,8 @@ def get_tasks(
details: Whether to include full task details
schedules_only: Whether to only include id, name and schedule
details
ignore_pagination: Whether to ignore pagination settings (filter
terms "first" and "rows"). Default is False.
"""
return self._send_and_transform_command(
Tasks.get_tasks(
Expand All @@ -3823,6 +3826,7 @@ def get_tasks(
trash=trash,
details=details,
schedules_only=schedules_only,
ignore_pagination=ignore_pagination,
)
)

Expand Down
6 changes: 6 additions & 0 deletions gvm/protocols/gmp/requests/v224/_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def get_tasks(
trash: Optional[bool] = None,
details: Optional[bool] = None,
schedules_only: Optional[bool] = None,
ignore_pagination: Optional[bool] = None,
) -> Request:
"""Request a list of tasks
Expand All @@ -210,6 +211,8 @@ def get_tasks(
details: Whether to include full task details
schedules_only: Whether to only include id, name and schedule
details
ignore_pagination: Whether to ignore pagination settings (filter
terms "first" and "rows"). Default is False.
"""
cmd = XmlCommand("get_tasks")
cmd.set_attribute("usage_type", "scan")
Expand All @@ -225,6 +228,9 @@ def get_tasks(
if schedules_only is not None:
cmd.set_attribute("schedules_only", to_bool(schedules_only))

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

return cmd

@classmethod
Expand Down
13 changes: 13 additions & 0 deletions tests/protocols/gmp/requests/v224/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,19 @@ def test_get_tasks_with_schedules_only(self):
b'<get_tasks usage_type="scan" schedules_only="0"/>',
)

def test_get_tasks_with_ignore_pagination(self):
request = Tasks().get_tasks(ignore_pagination=True)
self.assertEqual(
bytes(request),
b'<get_tasks usage_type="scan" ignore_pagination="1"/>',
)

request = Tasks().get_tasks(ignore_pagination=False)
self.assertEqual(
bytes(request),
b'<get_tasks usage_type="scan" ignore_pagination="0"/>',
)

def test_get_task(self):
request = Tasks().get_task("task_id")
self.assertEqual(
Expand Down
13 changes: 13 additions & 0 deletions tests/protocols/gmpv224/entities/tasks/test_get_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,16 @@ def test_get_tasks_with_schedules_only(self):
self.connection.send.has_been_called_with(
b'<get_tasks usage_type="scan" schedules_only="1"/>'
)

def test_get_tasks_with_ignore_pagination(self):
self.gmp.get_tasks(ignore_pagination=True)

self.connection.send.has_been_called_with(
b'<get_tasks usage_type="scan" ignore_pagination="1"/>'
)

self.gmp.get_tasks(ignore_pagination=False)

self.connection.send.has_been_called_with(
b'<get_tasks usage_type="scan" ignore_pagination="0"/>'
)

0 comments on commit 2bc27a2

Please sign in to comment.