Skip to content

Commit a796dbf

Browse files
committed
Improve typing and output for
lookup default_match field.
1 parent 32ced32 commit a796dbf

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

contentctl/objects/abstract_security_content_objects/detection_abstract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def serialize_model(self):
476476
"name": lookup.name,
477477
"description": lookup.description,
478478
"filename": lookup.filename.name,
479-
"default_match": "true" if lookup.default_match else "false",
479+
"default_match": lookup.default_match,
480480
"case_sensitive_match": "true"
481481
if lookup.case_sensitive_match
482482
else "false",

contentctl/objects/lookup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ class Lookup_Type(StrEnum):
6969

7070
# TODO (#220): Split Lookup into 2 classes
7171
class Lookup(SecurityContentObject, abc.ABC):
72-
default_match: Optional[bool] = None
72+
default_match: str = Field(default='', description="This field is given a default value of ''"
73+
"because it is the default value specified in the transforms.conf "
74+
"docs. Giving it a type of str rather than str | None simplifies "
75+
"the typing for the field.")
7376
# Per the documentation for transforms.conf, EXACT should not be specified in this list,
7477
# so we include only WILDCARD and CIDR
7578
match_type: list[Annotated[str, Field(pattern=r"(^WILDCARD|CIDR)\(.+\)$")]] = Field(
@@ -88,7 +91,7 @@ def serialize_model(self):
8891

8992
# All fields custom to this model
9093
model = {
91-
"default_match": "true" if self.default_match is True else "false",
94+
"default_match": self.default_match,
9295
"match_type": self.match_type_to_conf_format,
9396
"min_matches": self.min_matches,
9497
"max_matches": self.max_matches,

contentctl/output/templates/transforms.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ filename = {{ lookup.app_filename.name }}
77
collection = {{ lookup.collection }}
88
external_type = kvstore
99
{% endif %}
10-
{% if lookup.default_match is defined and lookup.default_match != None %}
11-
default_match = {{ lookup.default_match | lower }}
10+
{% if lookup.default_match != '' %}
11+
default_match = {{ lookup.default_match }}
1212
{% endif %}
1313
{% if lookup.case_sensitive_match is defined and lookup.case_sensitive_match != None %}
1414
case_sensitive_match = {{ lookup.case_sensitive_match | lower }}

0 commit comments

Comments
 (0)