From 0a3bd9130da267519b58eeaff5d9608e07c404f1 Mon Sep 17 00:00:00 2001 From: Justin Ibarra Date: Wed, 15 Sep 2021 20:12:39 -0800 Subject: [PATCH] Allow CLi config to be multiple formats (#1485) (cherry picked from commit 7179942be3fc962884f9c54d89906f405c6d6633) --- .gitignore | 2 +- detection_rules/misc.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index f0fc34cb8..302d627cd 100644 --- a/.gitignore +++ b/.gitignore @@ -107,7 +107,7 @@ ENV/ /_extras/ # detection rules -.detection-rules-cfg.json +.detection-rules-cfg.* releases/ collections/ enriched-rule-indexes/ diff --git a/detection_rules/misc.py b/detection_rules/misc.py index dca6ea966..f9a522d3e 100644 --- a/detection_rules/misc.py +++ b/detection_rules/misc.py @@ -4,11 +4,11 @@ # 2.0. """Misc support.""" -import json import os import re import time import uuid +from pathlib import Path from functools import wraps from typing import NoReturn @@ -252,14 +252,15 @@ def get_kibana_rules(*rule_paths, repo='elastic/kibana', branch='master', verbos @cached def parse_config(): """Parse a default config file.""" - config_file = get_path('.detection-rules-cfg.json') + import eql + + config_file = next(Path(get_path()).glob('.detection-rules-cfg.*'), None) config = {} - if os.path.exists(config_file): - with open(config_file) as f: - config = json.load(f) + if config_file and config_file.exists(): + config = eql.utils.load_dump(str(config_file)) - click.secho('Loaded config file: {}'.format(config_file), fg='yellow') + click.secho(f'Loaded config file: {config_file}', fg='yellow') return config