From 8236645481552725d7be5700675739d34b7d26ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Mon, 26 Feb 2024 14:20:41 +0100 Subject: [PATCH] Change: Use base enum class for most enums in python-gvm Some enums like ScannerType and AliveTest are special and don't need to be derived from our base enum class. Using our base enum class for all other enums allows to remove all from_string methods and therefore avoids code duplication. --- gvm/protocols/gmpv208/entities/alerts.py | 52 +------------ gvm/protocols/gmpv208/entities/audits.py | 1 - gvm/protocols/gmpv208/entities/credentials.py | 75 +------------------ gvm/protocols/gmpv208/entities/entities.py | 18 +---- gvm/protocols/gmpv208/entities/filter.py | 15 +--- gvm/protocols/gmpv208/entities/hosts.py | 25 +------ gvm/protocols/gmpv208/entities/notes.py | 1 - gvm/protocols/gmpv208/entities/permissions.py | 27 +------ gvm/protocols/gmpv208/entities/port_lists.py | 28 +------ .../gmpv208/entities/report_formats.py | 19 +---- gvm/protocols/gmpv208/entities/secinfo.py | 20 +---- gvm/protocols/gmpv208/entities/severity.py | 22 +----- gvm/protocols/gmpv208/entities/targets.py | 1 - gvm/protocols/gmpv208/entities/tasks.py | 1 - gvm/protocols/gmpv208/entities/tickets.py | 21 +----- .../gmpv208/entities/tls_certificates.py | 1 - gvm/protocols/gmpv208/entities/users.py | 22 +----- gvm/protocols/gmpv208/system/aggregates.py | 49 +----------- gvm/protocols/gmpv208/system/feed.py | 18 +---- gvm/protocols/gmpv208/system/help.py | 25 +------ gvm/protocols/gmpv214/entities/notes.py | 1 - gvm/protocols/gmpv214/entities/overrides.py | 1 - .../gmpv225/entities/resourcenames.py | 24 +----- gvm/protocols/gmpv225/system/version.py | 1 - 24 files changed, 30 insertions(+), 438 deletions(-) diff --git a/gvm/protocols/gmpv208/entities/alerts.py b/gvm/protocols/gmpv208/entities/alerts.py index 6e4e5605f..af87196ba 100644 --- a/gvm/protocols/gmpv208/entities/alerts.py +++ b/gvm/protocols/gmpv208/entities/alerts.py @@ -3,9 +3,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later # -from enum import Enum from typing import Any, Optional, Union +from gvm._enum import Enum from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument # if I use latest, I get circular import :/ @@ -24,23 +24,6 @@ class AlertEvent(Enum): ASSIGNED_TICKET_CHANGED = "Assigned ticket changed" OWNED_TICKET_CHANGED = "Owned ticket changed" - @classmethod - def from_string( - cls, - alert_event: Optional[str], - ) -> Optional["AlertEvent"]: - """Convert an alert event string into a AlertEvent instance""" - if not alert_event: - return None - - try: - return cls[alert_event.replace(" ", "_").upper()] - except KeyError: - raise InvalidArgument( - argument="alert_event", - function=cls.from_string.__name__, - ) from None - class AlertCondition(Enum): """Enum for alert condition types""" @@ -52,22 +35,6 @@ class AlertCondition(Enum): FILTER_COUNT_CHANGED = "Filter count changed" FILTER_COUNT_AT_LEAST = "Filter count at least" - @classmethod - def from_string( - cls, alert_condition: Optional[str] - ) -> Optional["AlertCondition"]: - """Convert an alert condition string into a AlertCondition instance""" - if not alert_condition: - return None - - try: - return cls[alert_condition.replace(" ", "_").upper()] - except KeyError: - raise InvalidArgument( - argument="alert_condition", - function=cls.from_string.__name__, - ) from None - class AlertMethod(Enum): """Enum for alert method type""" @@ -85,23 +52,6 @@ class AlertMethod(Enum): TIPPINGPOINT_SMS = "TippingPoint SMS" ALEMBA_VFIRE = "Alemba vFire" - @classmethod - def from_string( - cls, - alert_method: Optional[str], - ) -> Optional["AlertMethod"]: - """Convert an alert method string into a AlertCondition instance""" - if not alert_method: - return None - - try: - return cls[alert_method.replace(" ", "_").upper()] - except KeyError: - raise InvalidArgument( - argument="alert_method", - function=cls.from_string.__name__, - ) from None - def _check_event( event: AlertEvent, condition: AlertCondition, method: AlertMethod diff --git a/gvm/protocols/gmpv208/entities/audits.py b/gvm/protocols/gmpv208/entities/audits.py index b936f0bcc..3ee7b838e 100644 --- a/gvm/protocols/gmpv208/entities/audits.py +++ b/gvm/protocols/gmpv208/entities/audits.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - from collections.abc import Mapping from numbers import Integral from typing import Any, List, Optional diff --git a/gvm/protocols/gmpv208/entities/credentials.py b/gvm/protocols/gmpv208/entities/credentials.py index 23f61792a..d02e32cb7 100644 --- a/gvm/protocols/gmpv208/entities/credentials.py +++ b/gvm/protocols/gmpv208/entities/credentials.py @@ -3,11 +3,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - -from enum import Enum from typing import Any, Optional -from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument +from gvm._enum import Enum +from gvm.errors import InvalidArgumentType, RequiredArgument from gvm.utils import add_filter, to_bool from gvm.xml import XmlCommand @@ -21,22 +20,6 @@ class CredentialFormat(Enum): EXE = "exe" PEM = "pem" - @classmethod - def from_string( - cls, - credential_format: Optional[str], - ) -> Optional["CredentialFormat"]: - if not credential_format: - return None - - try: - return cls[credential_format.upper()] - except KeyError: - raise InvalidArgument( - argument="credential_format", - function=cls.from_string.__name__, - ) from None - class CredentialType(Enum): """Enum for credential types""" @@ -49,23 +32,6 @@ class CredentialType(Enum): PGP_ENCRYPTION_KEY = "pgp" PASSWORD_ONLY = "pw" - @classmethod - def from_string( - cls, - credential_type: Optional[str], - ) -> Optional["CredentialType"]: - """Convert a credential type string into a CredentialType instance""" - if not credential_type: - return None - - try: - return cls[credential_type.upper()] - except KeyError: - raise InvalidArgument( - argument="credential_type", - function=cls.from_string.__name__, - ) from None - class SnmpAuthAlgorithm(Enum): """Enum for SNMP auth algorithm""" @@ -73,24 +39,6 @@ class SnmpAuthAlgorithm(Enum): SHA1 = "sha1" MD5 = "md5" - @classmethod - def from_string( - cls, - algorithm: Optional[str], - ) -> Optional["SnmpAuthAlgorithm"]: - """Convert a SNMP auth algorithm string into a - SnmpAuthAlgorithm instance""" - if not algorithm: - return None - - try: - return cls[algorithm.upper()] - except KeyError: - raise InvalidArgument( - argument="algorithm", - function=cls.from_string.__name__, - ) from None - class SnmpPrivacyAlgorithm(Enum): """Enum for SNMP privacy algorithm""" @@ -98,25 +46,6 @@ class SnmpPrivacyAlgorithm(Enum): AES = "aes" DES = "des" - @classmethod - def from_string( - cls, - algorithm: Optional[str], - ) -> Optional["SnmpPrivacyAlgorithm"]: - """Convert a SNMP privacy algorithm string into a SnmpPrivacyAlgorithm - instance - """ - if not algorithm: - return None - - try: - return cls[algorithm.upper()] - except KeyError: - raise InvalidArgument( - argument="algorithm", - function=cls.from_string.__name__, - ) from None - class CredentialsMixin: def clone_credential(self, credential_id: str) -> Any: diff --git a/gvm/protocols/gmpv208/entities/entities.py b/gvm/protocols/gmpv208/entities/entities.py index 0e2f8a970..865964844 100644 --- a/gvm/protocols/gmpv208/entities/entities.py +++ b/gvm/protocols/gmpv208/entities/entities.py @@ -3,11 +3,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - -from enum import Enum from typing import Optional -from gvm.errors import InvalidArgument +from gvm._enum import Enum class EntityType(Enum): @@ -58,9 +56,6 @@ def from_string( Arguments: entity_type: Entity type string to convert to a EntityType """ - if not entity_type: - return None - if entity_type == "vuln": return cls.VULNERABILITY @@ -70,13 +65,4 @@ def from_string( if entity_type == "config": return cls.SCAN_CONFIG - if entity_type == "tls_certificate": - return cls.TLS_CERTIFICATE - - try: - return cls[entity_type.upper()] - except KeyError: - raise InvalidArgument( - argument="entity_type", - function=cls.from_string.__name__, - ) from None + return super().from_string(entity_type) diff --git a/gvm/protocols/gmpv208/entities/filter.py b/gvm/protocols/gmpv208/entities/filter.py index 1711a97d9..0402d06dd 100644 --- a/gvm/protocols/gmpv208/entities/filter.py +++ b/gvm/protocols/gmpv208/entities/filter.py @@ -3,10 +3,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later # -from enum import Enum from typing import Any, Optional -from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument +from gvm._enum import Enum +from gvm.errors import InvalidArgumentType, RequiredArgument from gvm.utils import add_filter, to_bool from gvm.xml import XmlCommand @@ -50,9 +50,6 @@ def from_string( Arguments: filter_type (str): Filter type string to convert to a FilterType """ - if not filter_type: - return None - if filter_type == "vuln": return cls.VULNERABILITY @@ -65,13 +62,7 @@ def from_string( if filter_type == "secinfo": return cls.ALL_SECINFO - try: - return cls[filter_type.upper()] - except KeyError: - raise InvalidArgument( - argument="filter_type", - function=cls.from_string.__name__, - ) from None + return super().from_string(filter_type) class FiltersMixin: diff --git a/gvm/protocols/gmpv208/entities/hosts.py b/gvm/protocols/gmpv208/entities/hosts.py index 682e37abc..0aa7171dc 100644 --- a/gvm/protocols/gmpv208/entities/hosts.py +++ b/gvm/protocols/gmpv208/entities/hosts.py @@ -3,11 +3,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - -from enum import Enum from typing import Any, Optional -from gvm.errors import InvalidArgument, RequiredArgument +from gvm._enum import Enum +from gvm.errors import RequiredArgument from gvm.utils import add_filter, to_bool from gvm.xml import XmlCommand @@ -19,26 +18,6 @@ class HostsOrdering(Enum): RANDOM = "random" REVERSE = "reverse" - @classmethod - def from_string( - cls, - hosts_ordering: Optional[str], - ) -> Optional["HostsOrdering"]: - """Convert a hosts ordering string to an actual HostsOrdering instance - - Arguments: - hosts_ordering: Host ordering string to convert to a HostsOrdering - """ - if not hosts_ordering: - return None - try: - return cls[hosts_ordering.upper()] - except KeyError: - raise InvalidArgument( - argument="hosts_ordering", - function=cls.from_string.__name__, - ) from None - class HostsMixin: def create_host(self, name: str, *, comment: Optional[str] = None) -> Any: diff --git a/gvm/protocols/gmpv208/entities/notes.py b/gvm/protocols/gmpv208/entities/notes.py index 2297b1f66..fb1f98560 100644 --- a/gvm/protocols/gmpv208/entities/notes.py +++ b/gvm/protocols/gmpv208/entities/notes.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - from typing import Any, List, Optional from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument diff --git a/gvm/protocols/gmpv208/entities/permissions.py b/gvm/protocols/gmpv208/entities/permissions.py index 0a115973e..f2ce51b37 100644 --- a/gvm/protocols/gmpv208/entities/permissions.py +++ b/gvm/protocols/gmpv208/entities/permissions.py @@ -3,10 +3,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later # -from enum import Enum from typing import Any, Optional -from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument +from gvm._enum import Enum +from gvm.errors import InvalidArgumentType, RequiredArgument from gvm.protocols.gmpv208.entities.entities import EntityType from gvm.utils import add_filter, to_bool from gvm.xml import XmlCommand @@ -19,29 +19,6 @@ class PermissionSubjectType(Enum): GROUP = "group" ROLE = "role" - @classmethod - def from_string( - cls, - subject_type: Optional[str], - ) -> Optional["PermissionSubjectType"]: - """Convert a permission subject type string to an actual - PermissionSubjectType instance - - Arguments: - subject_type: Permission subject type string to convert to a - PermissionSubjectType - """ - if not subject_type: - return None - - try: - return cls[subject_type.upper()] - except KeyError: - raise InvalidArgument( - argument="subject_type", - function=cls.from_string.__name__, - ) from None - class PermissionsMixin: def clone_permission(self, permission_id: str) -> Any: diff --git a/gvm/protocols/gmpv208/entities/port_lists.py b/gvm/protocols/gmpv208/entities/port_lists.py index 37f3ac6c9..8342514c3 100644 --- a/gvm/protocols/gmpv208/entities/port_lists.py +++ b/gvm/protocols/gmpv208/entities/port_lists.py @@ -3,11 +3,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - -from enum import Enum from typing import Any, Optional -from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument +from gvm._enum import Enum +from gvm.errors import InvalidArgumentType, RequiredArgument from gvm.utils import add_filter, to_bool from gvm.xml import XmlCommand @@ -18,29 +17,6 @@ class PortRangeType(Enum): TCP = "TCP" UDP = "UDP" - @classmethod - def from_string( - cls, - port_range_type: Optional[str], - ) -> Optional["PortRangeType"]: - """Convert a port range type string to an actual - PortRangeType instance - - Arguments: - port_range_type: Port range type string to - convert to a PortRangeType - """ - if not port_range_type: - return None - - try: - return cls[port_range_type.upper()] - except KeyError: - raise InvalidArgument( - argument="port_range_type", - function=cls.from_string.__name__, - ) from None - class PortListMixin: def clone_port_list(self, port_list_id: str) -> Any: diff --git a/gvm/protocols/gmpv208/entities/report_formats.py b/gvm/protocols/gmpv208/entities/report_formats.py index 7ae27fbec..b87975d85 100644 --- a/gvm/protocols/gmpv208/entities/report_formats.py +++ b/gvm/protocols/gmpv208/entities/report_formats.py @@ -3,11 +3,11 @@ # SPDX-License-Identifier: GPL-3.0-or-later # -from enum import Enum from typing import Any, Optional, Union from lxml.etree import XMLSyntaxError +from gvm._enum import Enum from gvm.errors import InvalidArgument, RequiredArgument from gvm.utils import add_filter, to_bool from gvm.xml import XmlCommand @@ -36,23 +36,6 @@ class ReportFormatType(Enum): VERINICE_ITG = "50c9950a-f326-11e4-800c-28d24461215b" XML = "a994b278-1f62-11e1-96ac-406186ea4fc5" - @classmethod - def from_string( - cls, - report_format: Optional[str], - ) -> Optional["ReportFormatType"]: - """Convert an report format name into a ReportFormatType instance""" - if not report_format: - return None - - try: - return cls[report_format.replace(" ", "_").upper()] - except KeyError: - raise InvalidArgument( - argument="report_format", - function=cls.from_string.__name__, - ) from KeyError - class ReportFormatsMixin: def clone_report_format( diff --git a/gvm/protocols/gmpv208/entities/secinfo.py b/gvm/protocols/gmpv208/entities/secinfo.py index 749c7c867..582718694 100644 --- a/gvm/protocols/gmpv208/entities/secinfo.py +++ b/gvm/protocols/gmpv208/entities/secinfo.py @@ -3,10 +3,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later # -from enum import Enum from typing import Any, Optional -from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument +from gvm._enum import Enum +from gvm.errors import InvalidArgumentType, RequiredArgument from gvm.utils import add_filter, to_bool from gvm.xml import XmlCommand @@ -21,22 +21,6 @@ class InfoType(Enum): OVALDEF = "OVALDEF" NVT = "NVT" - @classmethod - def from_string(cls, info_type: Optional[str]) -> Optional["InfoType"]: - """Convert a info type string to an actual InfoType instance - - Arguments: - info_type: Info type string to convert to a InfoType - """ - if not info_type: - return None - try: - return cls[info_type.upper()] - except KeyError: - raise InvalidArgument( - argument="info_type", function=cls.from_string.__name__ - ) from None - class SecInfoMixin: def get_nvt_families(self, *, sort_order: Optional[str] = None): diff --git a/gvm/protocols/gmpv208/entities/severity.py b/gvm/protocols/gmpv208/entities/severity.py index 721070946..d19fb8df5 100644 --- a/gvm/protocols/gmpv208/entities/severity.py +++ b/gvm/protocols/gmpv208/entities/severity.py @@ -3,12 +3,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - -from enum import Enum from numbers import Real -from typing import Optional -from gvm.errors import InvalidArgument +from gvm._enum import Enum Severity = Real @@ -22,20 +19,3 @@ class SeverityLevel(Enum): LOG = "Log" ALARM = "Alarm" DEBUG = "Debug" - - @classmethod - def from_string( - cls, - severity_level: Optional[str], - ) -> Optional["SeverityLevel"]: - """Convert a severity level string into a SeverityLevel instance""" - if not severity_level: - return None - - try: - return cls[severity_level.upper()] - except KeyError: - raise InvalidArgument( - argument="severity_level", - function=cls.from_string.__name__, - ) from None diff --git a/gvm/protocols/gmpv208/entities/targets.py b/gvm/protocols/gmpv208/entities/targets.py index fcbb9e8fb..bab3b73f6 100644 --- a/gvm/protocols/gmpv208/entities/targets.py +++ b/gvm/protocols/gmpv208/entities/targets.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - from enum import Enum from typing import Any, List, Optional diff --git a/gvm/protocols/gmpv208/entities/tasks.py b/gvm/protocols/gmpv208/entities/tasks.py index cb4c9690a..b3c1fb584 100644 --- a/gvm/protocols/gmpv208/entities/tasks.py +++ b/gvm/protocols/gmpv208/entities/tasks.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - from collections.abc import Mapping from numbers import Integral from typing import Any, List, Optional diff --git a/gvm/protocols/gmpv208/entities/tickets.py b/gvm/protocols/gmpv208/entities/tickets.py index 39f7a734c..cfdcddb78 100644 --- a/gvm/protocols/gmpv208/entities/tickets.py +++ b/gvm/protocols/gmpv208/entities/tickets.py @@ -3,10 +3,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later # -from enum import Enum from typing import Any, Optional -from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument +from gvm._enum import Enum +from gvm.errors import InvalidArgumentType, RequiredArgument from gvm.utils import add_filter, to_bool from gvm.xml import XmlCommand @@ -18,23 +18,6 @@ class TicketStatus(Enum): FIXED = "Fixed" CLOSED = "Closed" - @classmethod - def from_string( - cls, - ticket_status: Optional[str], - ) -> Optional["TicketStatus"]: - """Convert a ticket status string into a TicketStatus instance""" - if not ticket_status: - return None - - try: - return cls[ticket_status.upper()] - except KeyError: - raise InvalidArgument( - argument="ticket_status", - function=cls.from_string.__name__, - ) from None - class TicketsMixin: def clone_ticket(self, ticket_id: str) -> Any: diff --git a/gvm/protocols/gmpv208/entities/tls_certificates.py b/gvm/protocols/gmpv208/entities/tls_certificates.py index 729c2f67d..010469f7f 100644 --- a/gvm/protocols/gmpv208/entities/tls_certificates.py +++ b/gvm/protocols/gmpv208/entities/tls_certificates.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - from typing import Any, Optional from gvm.errors import RequiredArgument diff --git a/gvm/protocols/gmpv208/entities/users.py b/gvm/protocols/gmpv208/entities/users.py index a7b8439f0..13cfa036e 100644 --- a/gvm/protocols/gmpv208/entities/users.py +++ b/gvm/protocols/gmpv208/entities/users.py @@ -3,11 +3,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - -from enum import Enum from typing import Any, List, Optional -from gvm.errors import InvalidArgument, RequiredArgument +from gvm._enum import Enum +from gvm.errors import RequiredArgument from gvm.utils import add_filter, to_bool, to_comma_list from gvm.xml import XmlCommand @@ -19,23 +18,6 @@ class UserAuthType(Enum): LDAP_CONNECT = "ldap_connect" RADIUS_CONNECT = "radius_connect" - @classmethod - def from_string( - cls, - user_auth_type: Optional[str], - ) -> Optional["UserAuthType"]: - """Convert a user auth type string into a UserAuthType instance""" - if not user_auth_type: - return None - - try: - return cls[user_auth_type.upper()] - except KeyError: - raise InvalidArgument( - argument="user_auth_type", - function=cls.from_string.__name__, - ) from None - class UsersMixin: def clone_user(self, user_id: str) -> Any: diff --git a/gvm/protocols/gmpv208/system/aggregates.py b/gvm/protocols/gmpv208/system/aggregates.py index a4a2d067f..03d7a4e02 100644 --- a/gvm/protocols/gmpv208/system/aggregates.py +++ b/gvm/protocols/gmpv208/system/aggregates.py @@ -3,10 +3,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later # -from enum import Enum from typing import Any, Optional -from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument +from gvm._enum import Enum +from gvm.errors import InvalidArgumentType, RequiredArgument # if I use latest, I get circular import :/ from gvm.protocols.gmpv208.entities.entities import EntityType @@ -27,30 +27,6 @@ class AggregateStatistic(Enum): TEXT = "text" # Text column value VALUE = "value" # Group or subgroup column value - @classmethod - def from_string( - cls, - aggregate_statistic: Optional[str], - ) -> Optional["AggregateStatistic"]: - """ - Convert a aggregate statistic string to an actual AggregateStatistic - instance. - - Arguments: - aggregate_statistic: Aggregate statistic string to convert to a - AggregateStatistic - """ - if not aggregate_statistic: - return None - - try: - return cls[aggregate_statistic.upper()] - except KeyError: - raise InvalidArgument( - argument="aggregate_statistic", - function=cls.from_string.__name__, - ) from None - class SortOrder(Enum): """Enum for sort order""" @@ -58,27 +34,6 @@ class SortOrder(Enum): ASCENDING = "ascending" DESCENDING = "descending" - @classmethod - def from_string( - cls, - sort_order: Optional[str], - ) -> Optional["SortOrder"]: - """ - Convert a sort order string to an actual SortOrder instance. - - Arguments: - sort_order: Sort order string to convert to a SortOrder - """ - if not sort_order: - return None - - try: - return cls[sort_order.upper()] - except KeyError: - raise InvalidArgument( - argument="sort_order", function=cls.from_string.__name__ - ) from None - class AggregatesMixin: def get_aggregates( diff --git a/gvm/protocols/gmpv208/system/feed.py b/gvm/protocols/gmpv208/system/feed.py index e5d06645e..42ce3a76d 100644 --- a/gvm/protocols/gmpv208/system/feed.py +++ b/gvm/protocols/gmpv208/system/feed.py @@ -3,11 +3,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - -from enum import Enum from typing import Any, Optional -from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument +from gvm._enum import Enum +from gvm.errors import InvalidArgumentType, RequiredArgument from gvm.xml import XmlCommand @@ -19,19 +18,6 @@ class FeedType(Enum): SCAP = "SCAP" GVMD_DATA = "GVMD_DATA" - @classmethod - def from_string(cls, feed_type: Optional[str]) -> Optional["FeedType"]: - """Convert a feed type string into a FeedType instance""" - if not feed_type: - return None - - try: - return cls[feed_type.upper()] - except KeyError: - raise InvalidArgument( - argument="feed_type", function=cls.from_string.__name__ - ) from None - class FeedMixin: def get_feeds(self) -> Any: diff --git a/gvm/protocols/gmpv208/system/help.py b/gvm/protocols/gmpv208/system/help.py index 8194033c4..233e34552 100644 --- a/gvm/protocols/gmpv208/system/help.py +++ b/gvm/protocols/gmpv208/system/help.py @@ -3,10 +3,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later # -from enum import Enum from typing import Any, Optional -from gvm.errors import InvalidArgument, InvalidArgumentType +from gvm._enum import Enum +from gvm.errors import InvalidArgumentType from gvm.xml import XmlCommand @@ -18,27 +18,6 @@ class HelpFormat(Enum): TEXT = "text" XML = "xml" - @classmethod - def from_string( - cls, - sort_order: Optional[str], - ) -> Optional["HelpFormat"]: - """ - Convert a sort order string to an actual SortOrder instance. - - Arguments: - sort_order: Sort order string to convert to a SortOrder - """ - if not sort_order: - return None - - try: - return cls[sort_order.upper()] - except KeyError: - raise InvalidArgument( - argument="sort_order", function=cls.from_string.__name__ - ) from None - class HelpMixin: def help( diff --git a/gvm/protocols/gmpv214/entities/notes.py b/gvm/protocols/gmpv214/entities/notes.py index bfaefa2ce..d0f07d8a5 100644 --- a/gvm/protocols/gmpv214/entities/notes.py +++ b/gvm/protocols/gmpv214/entities/notes.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - from typing import Any, List, Optional from gvm.errors import InvalidArgument, RequiredArgument diff --git a/gvm/protocols/gmpv214/entities/overrides.py b/gvm/protocols/gmpv214/entities/overrides.py index 550b87032..1aad3fbce 100644 --- a/gvm/protocols/gmpv214/entities/overrides.py +++ b/gvm/protocols/gmpv214/entities/overrides.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - from typing import Any, List, Optional from gvm.errors import InvalidArgument, RequiredArgument diff --git a/gvm/protocols/gmpv225/entities/resourcenames.py b/gvm/protocols/gmpv225/entities/resourcenames.py index 4ca35ea21..443f6cfad 100644 --- a/gvm/protocols/gmpv225/entities/resourcenames.py +++ b/gvm/protocols/gmpv225/entities/resourcenames.py @@ -3,11 +3,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - -from enum import Enum from typing import Any, Optional -from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument +from gvm._enum import Enum +from gvm.errors import InvalidArgumentType, RequiredArgument from gvm.utils import add_filter from gvm.xml import XmlCommand @@ -42,25 +41,6 @@ class ResourceType(Enum): TLS_CERTIFICATE = "TLS_CERTIFICATE" USER = "USER" - @classmethod - def from_string( - cls, - resource_type: Optional[str], - ) -> Optional["ResourceType"]: - """Convert a resource type string to an actual ResourceType instance - - Arguments: - resource_type: Resource type string to convert to a ResourceType - """ - if not resource_type: - return None - try: - return cls[resource_type.upper()] - except KeyError: - raise InvalidArgument( - argument="resource_type", function=cls.from_string.__name__ - ) from None - class ResourceNamesMixin: def get_resource_names_list( diff --git a/gvm/protocols/gmpv225/system/version.py b/gvm/protocols/gmpv225/system/version.py index 190480ff1..e879c29fd 100644 --- a/gvm/protocols/gmpv225/system/version.py +++ b/gvm/protocols/gmpv225/system/version.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later # - from gvm.protocols.gmpv208.system.version import ( VersionMixin as Gmp208VersionMixin, )