Skip to content

Commit be8a803

Browse files
authored
Merge branch 'main' into dependabot/pip/setuptools-gte-69.5.1-and-lt-75.0.0
2 parents c94b9bf + 39f1d94 commit be8a803

File tree

7 files changed

+21
-13
lines changed

7 files changed

+21
-13
lines changed

contentctl/enrichments/attack_enrichment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Annotated,Any
1111
from contentctl.objects.mitre_attack_enrichment import MitreAttackEnrichment
1212
from contentctl.objects.config import validate
13+
from contentctl.objects.annotated_types import MITRE_ATTACK_ID_TYPE
1314
logging.getLogger('taxii2client').setLevel(logging.CRITICAL)
1415

1516

@@ -23,7 +24,7 @@ def getAttackEnrichment(config:validate)->AttackEnrichment:
2324
_ = enrichment.get_attack_lookup(str(config.path))
2425
return enrichment
2526

26-
def getEnrichmentByMitreID(self, mitre_id:Annotated[str, Field(pattern=r"^T\d{4}(.\d{3})?$")])->MitreAttackEnrichment:
27+
def getEnrichmentByMitreID(self, mitre_id:MITRE_ATTACK_ID_TYPE)->MitreAttackEnrichment:
2728
if not self.use_enrichment:
2829
raise Exception(f"Error, trying to add Mitre Enrichment, but use_enrichment was set to False")
2930

contentctl/enrichments/cve_enrichment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pydantic import BaseModel,Field, computed_field
99
from decimal import Decimal
1010
from requests.exceptions import ReadTimeout
11-
11+
from contentctl.objects.annotated_types import CVE_TYPE
1212
if TYPE_CHECKING:
1313
from contentctl.objects.config import validate
1414

@@ -18,7 +18,7 @@
1818

1919

2020
class CveEnrichmentObj(BaseModel):
21-
id: Annotated[str, r"^CVE-[1|2]\d{3}-\d+$"]
21+
id: CVE_TYPE
2222
cvss: Annotated[Decimal, Field(ge=.1, le=10, decimal_places=1)]
2323
summary: str
2424

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from pydantic import Field
2+
from typing import Annotated
3+
4+
CVE_TYPE = Annotated[str, Field(pattern=r"^CVE-[1|2]\d{3}-\d+$")]
5+
MITRE_ATTACK_ID_TYPE = Annotated[str, Field(pattern=r"^T\d{4}(.\d{3})?$")]
6+
APPID_TYPE = Annotated[str,Field(pattern="^[a-zA-Z0-9_-]+$")]

contentctl/objects/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from abc import ABC, abstractmethod
1919
from contentctl.objects.enums import PostTestBehavior, DetectionTestingMode
2020
from contentctl.objects.detection import Detection
21-
21+
from contentctl.objects.annotated_types import APPID_TYPE
2222
import tqdm
2323
from functools import partialmethod
2424

@@ -33,7 +33,7 @@ class App_Base(BaseModel,ABC):
3333
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
3434
uid: Optional[int] = Field(default=None)
3535
title: str = Field(description="Human-readable name used by the app. This can have special characters.")
36-
appid: Optional[Annotated[str, Field(pattern="^[a-zA-Z0-9_-]+$")]]= Field(default=None,description="Internal name used by your app. "
36+
appid: Optional[APPID_TYPE]= Field(default=None,description="Internal name used by your app. "
3737
"It may ONLY have characters, numbers, and underscores. No other characters are allowed.")
3838
version: str = Field(description="The version of your Content Pack. This must follow semantic versioning guidelines.")
3939
description: Optional[str] = Field(default="description of app",description="Free text description of the Content Pack.")
@@ -101,7 +101,7 @@ class CustomApp(App_Base):
101101
# https://docs.splunk.com/Documentation/Splunk/9.0.4/Admin/Appconf
102102
uid: int = Field(ge=2, lt=100000, default_factory=lambda:random.randint(20000,100000))
103103
title: str = Field(default="Content Pack",description="Human-readable name used by the app. This can have special characters.")
104-
appid: Annotated[str, Field(pattern="^[a-zA-Z0-9_-]+$")]= Field(default="ContentPack",description="Internal name used by your app. "
104+
appid: APPID_TYPE = Field(default="ContentPack",description="Internal name used by your app. "
105105
"It may ONLY have characters, numbers, and underscores. No other characters are allowed.")
106106
version: str = Field(default="0.0.1",description="The version of your Content Pack. This must follow semantic versioning guidelines.", validate_default=True)
107107

contentctl/objects/detection_tags.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
SecurityContentProductName
3434
)
3535
from contentctl.objects.atomic import AtomicTest
36-
36+
from contentctl.objects.annotated_types import MITRE_ATTACK_ID_TYPE, CVE_TYPE
3737

3838
# TODO (#266): disable the use_enum_values configuration
3939
class DetectionTags(BaseModel):
@@ -50,7 +50,7 @@ class DetectionTags(BaseModel):
5050
def risk_score(self) -> int:
5151
return round((self.confidence * self.impact)/100)
5252

53-
mitre_attack_id: List[Annotated[str, Field(pattern=r"^T\d{4}(.\d{3})?$")]] = []
53+
mitre_attack_id: List[MITRE_ATTACK_ID_TYPE] = []
5454
nist: list[NistCategory] = []
5555
observable: List[Observable] = []
5656
message: str = Field(...)
@@ -69,7 +69,7 @@ def risk_severity(self) -> RiskSeverity:
6969
else:
7070
return RiskSeverity('low')
7171

72-
cve: List[Annotated[str, r"^CVE-[1|2]\d{3}-\d+$"]] = []
72+
cve: List[CVE_TYPE] = []
7373
atomic_guid: List[AtomicTest] = []
7474
drilldown_search: Optional[str] = None
7575

contentctl/objects/mitre_attack_enrichment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import List, Annotated
44
from enum import StrEnum
55
import datetime
6+
from contentctl.objects.annotated_types import MITRE_ATTACK_ID_TYPE
67

78
class MitreTactics(StrEnum):
89
RECONNAISSANCE = "Reconnaissance"
@@ -85,7 +86,7 @@ def standardize_contributors(cls, contributors:list[str] | None) -> list[str]:
8586
# TODO (#266): disable the use_enum_values configuration
8687
class MitreAttackEnrichment(BaseModel):
8788
ConfigDict(use_enum_values=True)
88-
mitre_attack_id: Annotated[str, Field(pattern=r"^T\d{4}(.\d{3})?$")] = Field(...)
89+
mitre_attack_id: MITRE_ATTACK_ID_TYPE = Field(...)
8990
mitre_attack_technique: str = Field(...)
9091
mitre_attack_tactics: List[MitreTactics] = Field(...)
9192
mitre_attack_groups: List[str] = Field(...)

contentctl/objects/story_tags.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from contentctl.objects.mitre_attack_enrichment import MitreAttackEnrichment
88
from contentctl.objects.enums import StoryCategory, DataModel, KillChainPhase, SecurityContentProductName
9-
9+
from contentctl.objects.annotated_types import CVE_TYPE,MITRE_ATTACK_ID_TYPE
1010

1111
class StoryUseCase(str,Enum):
1212
FRAUD_DETECTION = "Fraud Detection"
@@ -27,10 +27,10 @@ class StoryTags(BaseModel):
2727

2828
# enrichment
2929
mitre_attack_enrichments: Optional[List[MitreAttackEnrichment]] = None
30-
mitre_attack_tactics: Optional[Set[Annotated[str, Field(pattern=r"^T\d{4}(.\d{3})?$")]]] = None
30+
mitre_attack_tactics: Optional[Set[MITRE_ATTACK_ID_TYPE]] = None
3131
datamodels: Optional[Set[DataModel]] = None
3232
kill_chain_phases: Optional[Set[KillChainPhase]] = None
33-
cve: List[Annotated[str, r"^CVE-[1|2]\d{3}-\d+$"]] = []
33+
cve: List[CVE_TYPE] = []
3434
group: List[str] = Field([], description="A list of groups who leverage the techniques list in this Analytic Story.")
3535

3636
def getCategory_conf(self) -> str:

0 commit comments

Comments
 (0)