Added error handling for CUSTOM_RULES_DIR, so that if the config file is not found in this directory, a more informative error message is now displayed suggesting to the user a method for fixing the issue.
How To Test
Set the CUSTOM_RULES_DIR environment variable to a non-existent directory, then run a detection rules command (e.g. setup-confg) as shown below.
(detection-rules-build) forteea1@forteea1-el1:/tmp/detection-rules$ export CUSTOM_RULES_DIR=/tmp/detection-rules/custom_rules_dir
(detection-rules-build) forteea1@forteea1-el1:/tmp/detection-rules$ python -m detection_rules custom-rules setup-config custom_rules_dir
Traceback (most recent call last):
File "<frozen runpy>", line 189, in _run_module_as_main
File "<frozen runpy>", line 148, in _get_module_details
File "<frozen runpy>", line 112, in _get_module_details
File "/tmp/detection-rules/detection_rules/__init__.py", line 13, in <module>
from . import ( # noqa: E402
File "/tmp/detection-rules/detection_rules/custom_schemas.py", line 17, in <module>
RULES_CONFIG = parse_rules_config()
^^^^^^^^^^^^^^^^^^^^
File "/tmp/detection-rules/detection_rules/utils.py", line 323, in wrapped
_cache[func_key][cache_key] = f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File "/tmp/detection-rules/detection_rules/config.py", line 215, in parse_rules_config
raise FileNotFoundError(
FileNotFoundError:
Configuration file not found.
Please create a configuration file. You may wish to use the 'setup-config' command
and update the 'CUSTOM_RULES_DIR' environment variable as needed.
Checklist
[ ] Added a label for the type of pr: bug, enhancement, schema, Rule: New, Rule: Deprecation, Rule: Tuning, Hunt: New, or Hunt: Tuning so guidelines can be generated
[ ] Added the meta:rapid-merge label if planning to merge within 24 hours
[ ] Secret and sensitive material has been managed correctly
[ ] Automated testing was updated or added to match the most common scenarios
[ ] Documentation and comments were added for features that require explanation
Pull Request
Issue link(s): https://github.com/elastic/detection-rules/issues/3989
Summary - What I changed
Added error handling for CUSTOM_RULES_DIR, so that if the config file is not found in this directory, a more informative error message is now displayed suggesting to the user a method for fixing the issue.
How To Test
Set the CUSTOM_RULES_DIR environment variable to a non-existent directory, then run a detection rules command (e.g. setup-confg) as shown below.
Checklist
bug
,enhancement
,schema
,Rule: New
,Rule: Deprecation
,Rule: Tuning
,Hunt: New
, orHunt: Tuning
so guidelines can be generatedmeta:rapid-merge
label if planning to merge within 24 hoursContributor checklist