Skip to content

Commit acf843d

Browse files
committed
Fix typing issue with default_match
field when detection is read from YML file with PyYAML
1 parent 39ce6bd commit acf843d

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

contentctl/input/director.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
import os
22
import sys
3-
from pathlib import Path
43
from dataclasses import dataclass, field
5-
from pydantic import ValidationError
4+
from pathlib import Path
65
from uuid import UUID
7-
from contentctl.input.yml_reader import YmlReader
86

9-
from contentctl.objects.detection import Detection
10-
from contentctl.objects.story import Story
7+
from pydantic import ValidationError
118

12-
from contentctl.objects.baseline import Baseline
13-
from contentctl.objects.investigation import Investigation
14-
from contentctl.objects.playbook import Playbook
15-
from contentctl.objects.deployment import Deployment
16-
from contentctl.objects.macro import Macro
17-
from contentctl.objects.lookup import LookupAdapter, Lookup
18-
from contentctl.objects.atomic import AtomicEnrichment
19-
from contentctl.objects.security_content_object import SecurityContentObject
20-
from contentctl.objects.data_source import DataSource
21-
from contentctl.objects.dashboard import Dashboard
229
from contentctl.enrichments.attack_enrichment import AttackEnrichment
2310
from contentctl.enrichments.cve_enrichment import CveEnrichment
24-
11+
from contentctl.helper.utils import Utils
12+
from contentctl.input.yml_reader import YmlReader
13+
from contentctl.objects.atomic import AtomicEnrichment
14+
from contentctl.objects.baseline import Baseline
2515
from contentctl.objects.config import validate
16+
from contentctl.objects.dashboard import Dashboard
17+
from contentctl.objects.data_source import DataSource
18+
from contentctl.objects.deployment import Deployment
19+
from contentctl.objects.detection import Detection
2620
from contentctl.objects.enums import SecurityContentType
27-
from contentctl.helper.utils import Utils
21+
from contentctl.objects.investigation import Investigation
22+
from contentctl.objects.lookup import Lookup, LookupAdapter
23+
from contentctl.objects.macro import Macro
24+
from contentctl.objects.playbook import Playbook
25+
from contentctl.objects.security_content_object import SecurityContentObject
26+
from contentctl.objects.story import Story
2827

2928

3029
@dataclass
@@ -113,9 +112,8 @@ def execute(self, input_dto: validate) -> None:
113112
self.createSecurityContent(SecurityContentType.detections)
114113
self.createSecurityContent(SecurityContentType.dashboards)
115114

116-
from contentctl.objects.abstract_security_content_objects.detection_abstract import (
117-
MISSING_SOURCES,
118-
)
115+
from contentctl.objects.abstract_security_content_objects.detection_abstract import \
116+
MISSING_SOURCES
119117

120118
if len(MISSING_SOURCES) > 0:
121119
missing_sources_string = "\n 🟡 ".join(sorted(list(MISSING_SOURCES)))

contentctl/objects/lookup.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import TYPE_CHECKING, Annotated, Any, Literal, Self
1010

1111
from pydantic import (
12+
BeforeValidator,
1213
Field,
1314
FilePath,
1415
NonNegativeInt,
@@ -69,7 +70,13 @@ class Lookup_Type(StrEnum):
6970

7071
# TODO (#220): Split Lookup into 2 classes
7172
class Lookup(SecurityContentObject, abc.ABC):
72-
default_match: str = Field(
73+
# We need to make sure that this is converted to a string because we widely
74+
# use the string "False" in our lookup content. However, PyYAML reads this
75+
# as a BOOL and this causes parsing to fail. As such, we will always
76+
# convert this to a string if it is passed as a bool
77+
default_match: Annotated[
78+
str, BeforeValidator(lambda dm: str(dm) if isinstance(dm, bool) else dm)
79+
] = Field(
7380
default="",
7481
description="This field is given a default value of ''"
7582
"because it is the default value specified in the transforms.conf "

0 commit comments

Comments
 (0)