[FR] Expand CUSTOM_RULES_DIR to support user relative paths (#5390)

* Add user relative path support
This commit is contained in:
Eric Forte
2025-12-03 12:19:29 -05:00
committed by GitHub
parent 634de61d6d
commit a8dbf2cf16
3 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -227,7 +227,7 @@ def parse_rules_config(path: Path | None = None) -> RulesConfig: # noqa: PLR091
raise ValueError(f"rules config file does not exist: {path}")
loaded = yaml.safe_load(path.read_text())
elif CUSTOM_RULES_DIR:
path = Path(CUSTOM_RULES_DIR) / "_config.yaml"
path = Path(CUSTOM_RULES_DIR).expanduser() / "_config.yaml"
if not path.exists():
raise FileNotFoundError(
"""
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "detection_rules"
version = "1.5.18"
version = "1.5.19"
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 Securitys Detection Engine."
readme = "README.md"
requires-python = ">=3.12"
+2 -2
View File
@@ -26,7 +26,7 @@ RULES_CONFIG = parse_rules_config()
def load_rules() -> RuleCollection:
if CUSTOM_RULES_DIR:
rc = RuleCollection()
path = Path(CUSTOM_RULES_DIR)
path = Path(CUSTOM_RULES_DIR).expanduser()
assert path.exists(), f"Custom rules directory {path} does not exist"
rc.load_directories(directories=RULES_CONFIG.rule_dirs)
rc.freeze()
@@ -62,7 +62,7 @@ class BaseRuleTest(unittest.TestCase):
RULE_LOADER_FAIL = True
RULE_LOADER_FAIL_MSG = str(e)
cls.custom_dir = Path(CUSTOM_RULES_DIR).resolve() if CUSTOM_RULES_DIR else None
cls.custom_dir = Path(CUSTOM_RULES_DIR).expanduser().resolve() if CUSTOM_RULES_DIR else None
cls.rules_config = RULES_CONFIG
@staticmethod