Skip to content

Commit 9402ae6

Browse files
trauttradebot-elastic
authored andcommitted
fix: Better aligning prompt behaviour with jsonschema types (#4894)
* Check for `["array"]` in addition to `"array"` * version bump * Exclude non-ecs-schema.json from CI check (cherry picked from commit c0631d2)
1 parent 67a8df1 commit 9402ae6

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

.github/workflows/version-code-and-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414
- '!hunting/**/*.md'
1515
- '!hunting/index.md'
1616
- '!hunting/**/*.toml'
17+
- '!detection_rules/etc/non-ecs-schema.json'
1718
types: [opened, reopened, synchronize, labeled, closed]
1819

1920
permissions:

detection_rules/cli_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ def rule_prompt( # noqa: PLR0912, PLR0913, PLR0915
256256
}
257257

258258
try:
259-
rule = TOMLRule(path=Path(path), contents=TOMLRuleContents.from_dict({"rule": contents, "metadata": meta}))
259+
rule_contents = TOMLRuleContents.from_dict({"rule": contents, "metadata": meta})
260+
rule = TOMLRule(path=Path(path), contents=rule_contents)
260261
except kql.KqlParseError as e:
261262
if skip_errors:
262263
return f"Rule: {kwargs['id']}, Rule Name: {rule_name} query failed to parse: {e.error_msg}"

detection_rules/misc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def schema_prompt(name: str, value: Any | None = None, is_required: bool = False
127127
if name == "rule_id":
128128
default = str(uuid.uuid4())
129129

130-
if len(enum) == 1 and is_required and field_type != "array":
130+
if len(enum) == 1 and is_required and field_type not in ("array", ["array"]):
131131
return enum[0]
132132

133133
def _check_type(_val: Any) -> bool: # noqa: PLR0911
@@ -163,7 +163,7 @@ def _convert_type(_val: Any) -> Any:
163163
name=name,
164164
default=f' [{default}] ("n/a" to leave blank) ' if default else "",
165165
required=" (required) " if is_required else "",
166-
multi=" (multi, comma separated) " if field_type == "array" else "",
166+
multi=(" (multi, comma separated) " if field_type in ("array", ["array"]) else ""),
167167
).strip()
168168
+ ": "
169169
)
@@ -179,7 +179,7 @@ def _convert_type(_val: Any) -> Any:
179179
continue
180180
return None
181181

182-
if field_type == "array":
182+
if field_type in ("array", ["array"]):
183183
result_list = result.split(",")
184184

185185
if not (min_item < len(result_list) < max_items):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "detection_rules"
3-
version = "1.3.8"
3+
version = "1.3.9"
44
description = "Detection Rules is the home for rules used by Elastic Security. This repository is used for the development, maintenance, testing, validation, and release of rules for Elastic Security’s Detection Engine."
55
readme = "README.md"
66
requires-python = ">=3.12"

0 commit comments

Comments
 (0)