Skip to content

Commit

Permalink
feat: Handle task endpoints, modify methods
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon committed May 20, 2024
1 parent f7de649 commit 0452404
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 5 deletions.
20 changes: 20 additions & 0 deletions src/gvm_sync_targets/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@
CreateAssetResponse,
DeleteAssetResponse,
GetAssetsResponse,
ModifyAssetResponse,
)
from gvm_sync_targets.models.auth_response import AuthenticateResponse
from gvm_sync_targets.models.response import Response
from gvm_sync_targets.models.targets_response import (
CreateTargetResponse,
DeleteTargetResponse,
GetTargetsResponse,
ModifyTargetResponse,
)
from gvm_sync_targets.models.tasks_response import (
CreateTaskResponse,
DeleteTaskResponse,
GetTasksResponse,
ModifyTaskResponse,
)
from gvm_sync_targets.util import Element

Expand All @@ -26,19 +34,31 @@
"AuthenticateResponse",
"DeleteAssetResponse",
"CreateAssetResponse",
"ModifyAssetResponse",
"GetTargetsResponse",
"DeleteTargetResponse",
"CreateTargetResponse",
"ModifyTargetResponse",
"GetTasksResponse",
"DeleteTaskResponse",
"CreateTaskResponse",
"ModifyTaskResponse",
]

_MODEL_MAP: Mapping[str, type[Response]] = {
"get_assets_response": GetAssetsResponse,
"authenticate_response": AuthenticateResponse,
"delete_asset_response": DeleteAssetResponse,
"create_asset_response": CreateAssetResponse,
"modify_asset_response": ModifyAssetResponse,
"get_targets_response": GetTargetsResponse,
"delete_target_response": DeleteTargetResponse,
"create_target_response": CreateTargetResponse,
"modify_target_response": ModifyTargetResponse,
"get_tasks_response": GetTasksResponse,
"delete_task_response": DeleteTaskResponse,
"create_task_response": CreateTaskResponse,
"modify_task_response": ModifyTaskResponse,
}


Expand Down
6 changes: 5 additions & 1 deletion src/gvm_sync_targets/models/assets_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class GetAssetsResponse(Response, tag="get_assets_response"):
filters: Filters
sort: Sort
pagination: Pagination = element("assets")
asset_count: Count = element("asset_count")
count: Count = element("asset_count")


class DeleteAssetResponse(Response, tag="delete_asset_response"):
Expand All @@ -96,3 +96,7 @@ class DeleteAssetResponse(Response, tag="delete_asset_response"):

class CreateAssetResponse(Response, tag="create_asset_response"):
uuid: str = attr("id")


class ModifyAssetResponse(Response, tag="modify_asset_response"):
pass
6 changes: 5 additions & 1 deletion src/gvm_sync_targets/models/targets_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class GetTargetsResponse(Response, tag="get_targets_response"):
filters: Filters
sort: Sort
pagination: Pagination = element("targets")
asset_count: Count = element("target_count")
count: Count = element("target_count")


class DeleteTargetResponse(Response, tag="delete_target_response"):
Expand All @@ -92,3 +92,7 @@ class DeleteTargetResponse(Response, tag="delete_target_response"):

class CreateTargetResponse(Response, tag="create_target_response"):
uuid: str = attr("id")


class ModifyTargetResponse(Response, tag="modify_target_response"):
pass
38 changes: 38 additions & 0 deletions src/gvm_sync_targets/models/tasks_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# SPDX-FileCopyrightText: 2024-present linuxdaemon <linuxdaemon.irc@gmail.com>
#
# SPDX-License-Identifier: MIT

from pydantic_xml import attr, element

from gvm_sync_targets.models.resource import (
Count,
Filters,
Pagination,
Resource,
Sort,
)
from gvm_sync_targets.models.response import Response


class Task(Resource, tag="task"):
pass


class GetTasksResponse(Response, tag="get_tasks_response"):
tasks: list[Task] = element()
filters: Filters
sort: Sort
pagination: Pagination = element("tasks")
count: Count = element("task_count")


class DeleteTaskResponse(Response, tag="delete_task_response"):
pass


class CreateTaskResponse(Response, tag="create_task_response"):
uuid: str = attr("id")


class ModifyTaskResponse(Response, tag="modify_tag_response"):
pass
4 changes: 2 additions & 2 deletions src/gvm_sync_targets/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ def get_all_hosts(
item: GetAssetsResponse = first
yield from item.assets
starting_index = 1
while starting_index < item.asset_count.filtered:
while starting_index < item.count.filtered:
keywords = item.filters.keywords.keywords
filter_string = " ".join(
f"{kw.column}{kw.relation}{kw.value}"
for kw in keywords
if kw.column != "first"
)

starting_index = item.pagination.start + item.asset_count.page
starting_index = item.pagination.start + item.count.page

if filter_string:
filter_string = f"first={starting_index} {filter_string}"
Expand Down
2 changes: 1 addition & 1 deletion tests/gvm_sync_targets/models/assets_response_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,4 +985,4 @@ def test_parse_model() -> None:
model = GetAssetsResponse.from_xml(data)
assert not model.model_extra
assert model.assets[0].identifiers.identifiers[0].source is not None
assert model.asset_count.total == 7
assert model.count.total == 7

0 comments on commit 0452404

Please sign in to comment.