Skip to content
Closed
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
3 changes: 3 additions & 0 deletions gvm/protocols/gmp/_gmp224.py
Original file line number Diff line number Diff line change
Expand Up @@ -3843,6 +3843,7 @@ def get_tasks(
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
task_limit: Optional[int] = None,
trash: Optional[bool] = None,
details: Optional[bool] = None,
schedules_only: Optional[bool] = None,
Expand All @@ -3853,6 +3854,7 @@ def get_tasks(
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
task_limit: Limits the amount of tasks being returned (Default:10)
trash: Whether to get the trashcan tasks instead
details: Whether to include full task details
schedules_only: Whether to only include id, name and schedule
Expand All @@ -3864,6 +3866,7 @@ def get_tasks(
Tasks.get_tasks(
filter_string=filter_string,
filter_id=filter_id,
task_limit=task_limit,
trash=trash,
details=details,
schedules_only=schedules_only,
Expand Down
8 changes: 8 additions & 0 deletions gvm/protocols/gmp/requests/v224/_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def get_tasks(
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
task_limit: Optional[int] = None,
trash: Optional[bool] = None,
details: Optional[bool] = None,
schedules_only: Optional[bool] = None,
Expand All @@ -207,6 +208,7 @@ def get_tasks(
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
task_limit: Limits the amount of tasks being returned (Default:10)
trash: Whether to get the trashcan tasks instead
details: Whether to include full task details
schedules_only: Whether to only include id, name and schedule
Expand All @@ -217,6 +219,12 @@ def get_tasks(
cmd = XmlCommand("get_tasks")
cmd.set_attribute("usage_type", "scan")

if task_limit is not None:
if filter_string is None:
filter_string = f"rows={task_limit}"
else:
filter_string += f" rows={task_limit}"

cmd.add_filter(filter_string, filter_id)

if trash is not None:
Expand Down
14 changes: 14 additions & 0 deletions tests/protocols/gmp/requests/v224/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,20 @@ def test_get_tasks_with_filter_id(self):
b'<get_tasks usage_type="scan" filt_id="filter_id"/>',
)

def test_get_tasks_with_task_limit(self):
request = Tasks().get_tasks(task_limit=5)
self.assertEqual(
bytes(request),
b'<get_tasks usage_type="scan" filter="rows=5"/>',
)

def test_get_tasks_with_task_limit_and_filter_string(self):
request = Tasks().get_tasks(filter_string="foo", task_limit=5)
self.assertEqual(
bytes(request),
b'<get_tasks usage_type="scan" filter="foo rows=5"/>',
)

def test_get_tasks_with_trash(self):
request = Tasks().get_tasks(trash=True)
self.assertEqual(
Expand Down
14 changes: 14 additions & 0 deletions tests/protocols/gmpv224/entities/tasks/test_get_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ def test_get_tasks_with_filter_id(self):
b'<get_tasks usage_type="scan" filt_id="f1"/>'
)

def test_get_tasks_with_task_limit(self):
self.gmp.get_tasks(task_limit="5")

self.connection.send.has_been_called_with(
b'<get_tasks usage_type="scan" filter="rows=5"/>'
)

def test_get_tasks_with_task_limit_and_filter_string(self):
self.gmp.get_tasks(filter_string="foo", task_limit="5")

self.connection.send.has_been_called_with(
b'<get_tasks usage_type="scan" filter="foo rows=5"/>'
)

def test_get_tasks_from_trash(self):
self.gmp.get_tasks(trash=True)

Expand Down