Skip to content

Commit

Permalink
Rework searching for rule product.
Browse files Browse the repository at this point in the history
No prodtype, now rule must be a part of some profile.
  • Loading branch information
mildas committed Jan 31, 2024
1 parent df5dd5e commit a78fd0d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions ctf/DiffStruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,17 @@ def get_rule_profiles(self, rule):
return profiles

def get_rule_products(self, rule):
products = []
# Parse from matched profiles product names
ruleyml_path = self.get_rule_ruleyml(rule)
prodtype_line = None
with open(ruleyml_path) as f:
for line in f.readlines():
if "prodtype:" in line:
prodtype_line = line
break
# rule.yml does not have prodtype
if not prodtype_line:
return None

prodtypes = re.match(r"\s*prodtype:\s*([\w|,]+)\s*", prodtype_line).group(1)
products = prodtypes.split(",")
for profile_path in self.find_rule_profiles(rule):
parse_file = re.match(r".+/((?:\w|-)+)/profiles/(?:\w|-)+\.profile",
profile_path)
products.append(parse_file.group(1))
# Find in controls and from controls get product
for control in self.find_rule_controls(rule):
for product in self.find_control_products(control):
products.append(product)

products = sorted(products, key=lambda k: (k!="rhel8", k!="rhel7", k!="ocp4", k))
return products

Expand Down

0 comments on commit a78fd0d

Please sign in to comment.