Skip to content

Commit 0a7db93

Browse files
allowing for new fields in DetectionMetadata
1 parent 1be4d87 commit 0a7db93

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

contentctl/actions/inspect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ def check_detection_metadata(self, config: inspect) -> None:
287287
app_name=config.app.label,
288288
appid=config.app.appid
289289
)
290+
290291
# Compare the conf files
291292
validation_errors: dict[str, list[MetadataValidationError]] = {}
292293
for rule_name in previous_build_conf.detection_stanzas:

contentctl/objects/abstract_security_content_objects/detection_abstract.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,11 @@ def metadata(self) -> dict[str, str|float]:
390390
# NOTE: we ignore the type error around self.status because we are using Pydantic's
391391
# use_enum_values configuration
392392
# https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.populate_by_name
393-
393+
394+
# NOTE: The `inspect` action is HIGHLY sensitive to the structure of the metadata line in
395+
# the detection stanza in savedsearches.conf. Additive operations (e.g. a new field in the
396+
# dict below) should not have any impact, but renaming or removing any of these fields will
397+
# break the `inspect` action.
394398
return {
395399
'detection_id': str(self.id),
396400
'deprecated': '1' if self.status == DetectionStatus.deprecated.value else '0', # type: ignore

contentctl/objects/detection_metadata.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66

77
class DetectionMetadata(BaseModel):
8+
"""
9+
A model of the metadata line in a detection stanza in savedsearches.conf
10+
"""
811
# A bool indicating whether the detection is deprecated (serialized as an int, 1 or 0)
912
deprecated: bool = Field(...)
1013

@@ -18,6 +21,10 @@ class DetectionMetadata(BaseModel):
1821
# The time the detection was published
1922
publish_time: float = Field(...)
2023

24+
class Config:
25+
# Allowing for future fields that may be added to the metadata JSON
26+
extra = "allow"
27+
2128
@field_validator("deprecated", mode="before")
2229
@classmethod
2330
def validate_deprecated(cls, v: Any) -> Any:

0 commit comments

Comments
 (0)