Catch invalid rules

This commit is contained in:
fleaz 2023-02-24 00:02:14 +01:00
parent ee3ef1879b
commit 78b3befcb3
No known key found for this signature in database
GPG key ID: AED15F8FDD04D083

View file

@ -65,15 +65,23 @@ def get_rules():
data = yaml.load(fh, Loader=Loader)
if data:
for rule in data:
if rule.get("name"):
name = rule.get("name", None)
description = rule.get("description", None)
if name == "" or description == "":
print("Found invalid rule with empty name or description string!")
print(rule)
sys.exit(1)
if name:
rule["name_regex"] = re.compile(rule["name"])
if rule.get("description"):
if description:
rule["desc_regex"] = re.compile(rule["description"])
else:
data = []
return data
else:
print(f"No rules.json found in {data_dir}! Did you run 'init'?")
print(f"No rules.yaml found in {data_dir}! Did you run 'init'?")
sys.exit(1)