Skip to content

Commit b5fcfd9

Browse files
Optimise Code
1 parent 2cfe620 commit b5fcfd9

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

tests/test_all_rules.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from detection_rules.rule_loader import FILE_PATTERN, RULES_CONFIG
3838
from detection_rules.rule_validators import EQLValidator, KQLValidator
3939
from detection_rules.schemas import definitions, get_min_supported_stack_version, get_stack_schemas
40-
from detection_rules.utils import INTEGRATION_RULE_DIR, PatchedTemplate, get_path, make_git
40+
from detection_rules.utils import ETC_DIR, INTEGRATION_RULE_DIR, PatchedTemplate, get_path, make_git
4141
from detection_rules.version_lock import loaded_version_lock
4242

4343
from .base import BaseRuleTest
@@ -1044,22 +1044,21 @@ def test_event_dataset(self):
10441044
def test_min_stack_version_supported(self):
10451045
failures = []
10461046
# Load supported stack versions from stack-schema-map.yaml
1047-
stack_map_path = Path("detection_rules/etc/stack-schema-map.yaml")
1047+
stack_map_path = Path(f"{ETC_DIR}/stack-schema-map.yaml")
10481048
with Path.open(stack_map_path) as f:
10491049
stack_map = yaml.safe_load(f)
10501050

10511051
# Get the minimum supported stack version (as string)
10521052
supported_versions = [v for v in stack_map if not v.startswith("#") and isinstance(v, str)]
1053-
min_supported = min(supported_versions, key=lambda v: tuple(map(int, v.split("."))))
1053+
def version_tuple(v):
1054+
return tuple(map(int, v.split(".")))
1055+
min_supported = min(supported_versions, key=version_tuple)
10541056
# Load all production rules
10551057
for rule in self.all_rules:
10561058
min_stack_version = rule.contents.metadata.get("min_stack_version")
10571059
if not min_stack_version:
10581060
continue # skip rules without min_stack_version
10591061
# Compare versions as tuples of ints
1060-
def version_tuple(v):
1061-
return tuple(map(int, v.split(".")))
1062-
10631062
if version_tuple(min_stack_version) < version_tuple(min_supported):
10641063
failures.append(
10651064
f"{self.rule_str(rule)}"

0 commit comments

Comments
 (0)