From 04524042ad0cf842f59941650d7ebd23ba70b289 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Mon, 20 May 2024 22:47:11 +0000 Subject: [PATCH] feat: Handle task endpoints, modify methods --- src/gvm_sync_targets/models/__init__.py | 20 ++++++++++ .../models/assets_response.py | 6 ++- .../models/targets_response.py | 6 ++- src/gvm_sync_targets/models/tasks_response.py | 38 +++++++++++++++++++ src/gvm_sync_targets/util.py | 4 +- .../models/assets_response_test.py | 2 +- 6 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 src/gvm_sync_targets/models/tasks_response.py diff --git a/src/gvm_sync_targets/models/__init__.py b/src/gvm_sync_targets/models/__init__.py index db3b38c..e8dd456 100644 --- a/src/gvm_sync_targets/models/__init__.py +++ b/src/gvm_sync_targets/models/__init__.py @@ -11,6 +11,7 @@ CreateAssetResponse, DeleteAssetResponse, GetAssetsResponse, + ModifyAssetResponse, ) from gvm_sync_targets.models.auth_response import AuthenticateResponse from gvm_sync_targets.models.response import Response @@ -18,6 +19,13 @@ CreateTargetResponse, DeleteTargetResponse, GetTargetsResponse, + ModifyTargetResponse, +) +from gvm_sync_targets.models.tasks_response import ( + CreateTaskResponse, + DeleteTaskResponse, + GetTasksResponse, + ModifyTaskResponse, ) from gvm_sync_targets.util import Element @@ -26,9 +34,15 @@ "AuthenticateResponse", "DeleteAssetResponse", "CreateAssetResponse", + "ModifyAssetResponse", "GetTargetsResponse", "DeleteTargetResponse", "CreateTargetResponse", + "ModifyTargetResponse", + "GetTasksResponse", + "DeleteTaskResponse", + "CreateTaskResponse", + "ModifyTaskResponse", ] _MODEL_MAP: Mapping[str, type[Response]] = { @@ -36,9 +50,15 @@ "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, } diff --git a/src/gvm_sync_targets/models/assets_response.py b/src/gvm_sync_targets/models/assets_response.py index c09cd0d..68eb77d 100644 --- a/src/gvm_sync_targets/models/assets_response.py +++ b/src/gvm_sync_targets/models/assets_response.py @@ -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"): @@ -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 diff --git a/src/gvm_sync_targets/models/targets_response.py b/src/gvm_sync_targets/models/targets_response.py index 85c5f2a..9ceb187 100644 --- a/src/gvm_sync_targets/models/targets_response.py +++ b/src/gvm_sync_targets/models/targets_response.py @@ -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"): @@ -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 diff --git a/src/gvm_sync_targets/models/tasks_response.py b/src/gvm_sync_targets/models/tasks_response.py new file mode 100644 index 0000000..56c406d --- /dev/null +++ b/src/gvm_sync_targets/models/tasks_response.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2024-present linuxdaemon +# +# 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 diff --git a/src/gvm_sync_targets/util.py b/src/gvm_sync_targets/util.py index 3698051..abc9218 100644 --- a/src/gvm_sync_targets/util.py +++ b/src/gvm_sync_targets/util.py @@ -43,7 +43,7 @@ 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}" @@ -51,7 +51,7 @@ def get_all_hosts( 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}" diff --git a/tests/gvm_sync_targets/models/assets_response_test.py b/tests/gvm_sync_targets/models/assets_response_test.py index c1deaf5..362ce3c 100644 --- a/tests/gvm_sync_targets/models/assets_response_test.py +++ b/tests/gvm_sync_targets/models/assets_response_test.py @@ -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