From c692b4cd94be5b8a4205a70dae73c85e26f44213 Mon Sep 17 00:00:00 2001 From: Thomas Patzke Date: Sun, 3 Nov 2024 01:39:30 +0100 Subject: [PATCH] Resolved import loop betwen base and attributes in sigma.rule. --- sigma/rule/__init__.py | 3 ++- sigma/rule/attributes.py | 6 +++++- sigma/rule/base.py | 13 ++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sigma/rule/__init__.py b/sigma/rule/__init__.py index 1b6c6f44..766608fb 100644 --- a/sigma/rule/__init__.py +++ b/sigma/rule/__init__.py @@ -1,8 +1,9 @@ from .rule import SigmaRule from .logsource import SigmaLogSource from .detection import SigmaDetection, SigmaDetectionItem, SigmaDetections -from .base import SigmaRuleBase, EnumLowercaseStringMixin, SigmaYAMLLoader +from .base import SigmaRuleBase, SigmaYAMLLoader from .attributes import ( + EnumLowercaseStringMixin, SigmaStatus, SigmaLevel, SigmaRelatedType, diff --git a/sigma/rule/attributes.py b/sigma/rule/attributes.py index 6cd9d7e6..489b833f 100644 --- a/sigma/rule/attributes.py +++ b/sigma/rule/attributes.py @@ -2,13 +2,17 @@ from typing import Optional, List, Type from uuid import UUID from enum import Enum, auto -from sigma.rule.base import EnumLowercaseStringMixin import sigma.exceptions as sigma_exceptions from sigma.exceptions import ( SigmaRuleLocation, ) +class EnumLowercaseStringMixin: + def __str__(self) -> str: + return self.name.lower() + + class SigmaStatus(EnumLowercaseStringMixin, Enum): UNSUPPORTED = auto() DEPRECATED = auto() diff --git a/sigma/rule/base.py b/sigma/rule/base.py index f6ed23b2..51ad063e 100644 --- a/sigma/rule/base.py +++ b/sigma/rule/base.py @@ -9,11 +9,6 @@ from sigma.rule.attributes import SigmaLevel, SigmaRelated, SigmaRuleTag, SigmaStatus -class EnumLowercaseStringMixin: - def __str__(self) -> str: - return self.name.lower() - - class SigmaYAMLLoader(yaml.SafeLoader): """Custom YAML loader implementing additional functionality for Sigma.""" @@ -35,18 +30,18 @@ class SigmaRuleBase: id: Optional[UUID] = None name: Optional[str] = None taxonomy: str = "sigma" - related: Optional[SigmaRelated] = None - status: Optional[SigmaStatus] = None + related: Optional["sigma.rule.attributes.SigmaRelated"] = None + status: Optional["sigma.rule.attributes.SigmaStatus"] = None description: Optional[str] = None license: Optional[str] = None references: List[str] = field(default_factory=list) - tags: List[SigmaRuleTag] = field(default_factory=list) + tags: List["sigma.rule.attributes.SigmaRuleTag"] = field(default_factory=list) author: Optional[str] = None date: Optional["datetime.date"] = None modified: Optional["datetime.date"] = None fields: List[str] = field(default_factory=list) falsepositives: List[str] = field(default_factory=list) - level: Optional[SigmaLevel] = None + level: Optional["sigma.rule.attributes.SigmaLevel"] = None scope: Optional[List[str]] = None errors: List[sigma_exceptions.SigmaError] = field(default_factory=list)