diff --git a/gvm/protocols/gmp/requests/__init__.py b/gvm/protocols/gmp/requests/__init__.py index fdadd0a73..7592df0b4 100644 --- a/gvm/protocols/gmp/requests/__init__.py +++ b/gvm/protocols/gmp/requests/__init__.py @@ -4,6 +4,7 @@ from ._aggregates import Aggregates, AggregateStatistic, SortOrder from ._auth import Authentication +from ._entity_id import EntityID from ._entity_type import EntityType from ._feed import Feed, FeedType from ._help import Help, HelpFormat @@ -18,6 +19,7 @@ "Aggregates", "AggregateStatistic", "Authentication", + "EntityID", "EntityType", "Feed", "FeedType", diff --git a/gvm/protocols/gmp/requests/_aggregates.py b/gvm/protocols/gmp/requests/_aggregates.py index b0a64ca63..e3f4b60aa 100644 --- a/gvm/protocols/gmp/requests/_aggregates.py +++ b/gvm/protocols/gmp/requests/_aggregates.py @@ -3,13 +3,13 @@ # SPDX-License-Identifier: GPL-3.0-or-later from typing import Iterable, Optional, Union -from uuid import UUID from gvm._enum import Enum from gvm.errors import InvalidArgumentType, RequiredArgument from gvm.protocols.core import Request from gvm.xml import XmlCommand +from ._entity_id import EntityID from ._entity_type import EntityType @@ -41,7 +41,7 @@ def get_aggregates( resource_type: Union[EntityType, str], *, filter_string: Optional[str] = None, - filter_id: Optional[Union[str, UUID]] = None, + filter_id: Optional[EntityID] = None, sort_criteria: Optional[ Iterable[dict[str, Union[str, SortOrder, AggregateStatistic]]] ] = None, diff --git a/gvm/protocols/gmp/requests/_entity_id.py b/gvm/protocols/gmp/requests/_entity_id.py new file mode 100644 index 000000000..4a3aa253a --- /dev/null +++ b/gvm/protocols/gmp/requests/_entity_id.py @@ -0,0 +1,8 @@ +# SPDX-FileCopyrightText: 2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later + +from typing import Union +from uuid import UUID + +EntityID = Union[str, UUID] diff --git a/gvm/protocols/gmp/requests/_port_list.py b/gvm/protocols/gmp/requests/_port_list.py index 05717411e..c0687a016 100644 --- a/gvm/protocols/gmp/requests/_port_list.py +++ b/gvm/protocols/gmp/requests/_port_list.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later from typing import Optional, Union -from uuid import UUID from gvm._enum import Enum from gvm.errors import RequiredArgument @@ -11,6 +10,8 @@ from gvm.utils import to_bool from gvm.xml import XmlCommand +from ._entity_id import EntityID + class PortRangeType(Enum): """Enum for port range type""" @@ -21,7 +22,7 @@ class PortRangeType(Enum): class PortList: @classmethod - def clone_port_list(cls, port_list_id: Union[str, UUID]) -> Request: + def clone_port_list(cls, port_list_id: EntityID) -> Request: """Clone an existing port list Args: @@ -70,7 +71,7 @@ def create_port_list( @classmethod def create_port_range( cls, - port_list_id: Union[str, UUID], + port_list_id: EntityID, start: int, end: int, port_range_type: Union[str, PortRangeType], @@ -124,7 +125,7 @@ def create_port_range( @classmethod def delete_port_list( - cls, port_list_id: Union[str, UUID], *, ultimate: bool = False + cls, port_list_id: EntityID, *, ultimate: bool = False ) -> Request: """Deletes an existing port list @@ -144,7 +145,7 @@ def delete_port_list( return cmd @classmethod - def delete_port_range(cls, port_range_id: Union[str, UUID]) -> Request: + def delete_port_range(cls, port_range_id: EntityID) -> Request: """Deletes an existing port range Args: @@ -166,7 +167,7 @@ def get_port_lists( cls, *, filter_string: Optional[str] = None, - filter_id: Optional[Union[str, UUID]] = None, + filter_id: Optional[EntityID] = None, details: Optional[bool] = None, targets: Optional[bool] = None, trash: Optional[bool] = None, @@ -196,7 +197,7 @@ def get_port_lists( return cmd @classmethod - def get_port_list(cls, port_list_id: Union[str, UUID]) -> Request: + def get_port_list(cls, port_list_id: EntityID) -> Request: """Request a single port list Args: @@ -219,7 +220,7 @@ def get_port_list(cls, port_list_id: Union[str, UUID]) -> Request: @classmethod def modify_port_list( cls, - port_list_id: Union[str, UUID], + port_list_id: EntityID, *, comment: Optional[str] = None, name: Optional[str] = None, diff --git a/gvm/protocols/gmp/requests/_resource_names.py b/gvm/protocols/gmp/requests/_resource_names.py index c39a1626f..6caf832d9 100644 --- a/gvm/protocols/gmp/requests/_resource_names.py +++ b/gvm/protocols/gmp/requests/_resource_names.py @@ -3,13 +3,14 @@ # SPDX-License-Identifier: GPL-3.0-or-later from typing import Optional, Union -from uuid import UUID from gvm._enum import Enum from gvm.errors import RequiredArgument from gvm.protocols.core import Request from gvm.xml import XmlCommand +from ._entity_id import EntityID + class ResourceType(Enum): """Enum for resource types""" @@ -79,7 +80,7 @@ def get_resource_names( @classmethod def get_resource_name( cls, - resource_id: Union[str, UUID], + resource_id: EntityID, resource_type: Union[ResourceType, str], ) -> Request: """Request a single resource name diff --git a/gvm/protocols/gmp/requests/_system_reports.py b/gvm/protocols/gmp/requests/_system_reports.py index ae7ed967c..01d2857b1 100644 --- a/gvm/protocols/gmp/requests/_system_reports.py +++ b/gvm/protocols/gmp/requests/_system_reports.py @@ -4,14 +4,15 @@ # from numbers import Integral -from typing import Optional, Union -from uuid import UUID +from typing import Optional from gvm.errors import InvalidArgument from gvm.protocols.core import Request from gvm.utils import to_bool from gvm.xml import XmlCommand +from ._entity_id import EntityID + class SystemReports: @classmethod @@ -23,7 +24,7 @@ def get_system_reports( start_time: Optional[str] = None, end_time: Optional[str] = None, brief: Optional[bool] = None, - slave_id: Optional[Union[str, UUID]] = None, + slave_id: Optional[EntityID] = None, ) -> Request: """Request a list of system reports diff --git a/gvm/protocols/gmp/requests/_trashcan.py b/gvm/protocols/gmp/requests/_trashcan.py index 8b4d62f82..45512b58a 100644 --- a/gvm/protocols/gmp/requests/_trashcan.py +++ b/gvm/protocols/gmp/requests/_trashcan.py @@ -2,13 +2,12 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -from typing import Union -from uuid import UUID - from gvm.errors import RequiredArgument from gvm.protocols.core import Request from gvm.xml import XmlCommand +from ._entity_id import EntityID + class TrashCan: @staticmethod @@ -21,7 +20,7 @@ def empty_trashcan() -> Request: return XmlCommand("empty_trashcan") @classmethod - def restore_from_trashcan(cls, entity_id: Union[str, UUID]) -> Request: + def restore_from_trashcan(cls, entity_id: EntityID) -> Request: """Restore an entity from the trashcan Args: diff --git a/gvm/protocols/gmp/requests/_user_settings.py b/gvm/protocols/gmp/requests/_user_settings.py index b941ef957..7a23c1ae1 100644 --- a/gvm/protocols/gmp/requests/_user_settings.py +++ b/gvm/protocols/gmp/requests/_user_settings.py @@ -3,14 +3,15 @@ # SPDX-License-Identifier: GPL-3.0-or-later # -from typing import Optional, Union -from uuid import UUID +from typing import Optional from gvm.errors import RequiredArgument from gvm.protocols.core import Request from gvm.utils import to_base64 from gvm.xml import XmlCommand +from ._entity_id import EntityID + class UserSettings: @staticmethod @@ -28,7 +29,7 @@ def get_user_settings(*, filter_string: Optional[str] = None) -> Request: return cmd @classmethod - def get_user_setting(cls, setting_id: Union[str, UUID]) -> Request: + def get_user_setting(cls, setting_id: EntityID) -> Request: """Request a single user setting Args: @@ -48,7 +49,7 @@ def get_user_setting(cls, setting_id: Union[str, UUID]) -> Request: def modify_user_setting( cls, *, - setting_id: Optional[Union[str, UUID]] = None, + setting_id: Optional[EntityID] = None, name: Optional[str] = None, value: Optional[str] = None, ) -> Request: