[FR] Expand CUSTOM_RULES_DIR to support user relative paths (#5390)
* Add user relative path support
This commit is contained in:
@@ -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
@@ -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 Security’s Detection Engine."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user