Skip to content

Commit a78fd0d

Browse files
committed
Rework searching for rule product.
No prodtype, now rule must be a part of some profile.
1 parent df5dd5e commit a78fd0d

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

ctf/DiffStruct.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,17 @@ def get_rule_profiles(self, rule):
119119
return profiles
120120

121121
def get_rule_products(self, rule):
122+
products = []
122123
# Parse from matched profiles product names
123-
ruleyml_path = self.get_rule_ruleyml(rule)
124-
prodtype_line = None
125-
with open(ruleyml_path) as f:
126-
for line in f.readlines():
127-
if "prodtype:" in line:
128-
prodtype_line = line
129-
break
130-
# rule.yml does not have prodtype
131-
if not prodtype_line:
132-
return None
133-
134-
prodtypes = re.match(r"\s*prodtype:\s*([\w|,]+)\s*", prodtype_line).group(1)
135-
products = prodtypes.split(",")
124+
for profile_path in self.find_rule_profiles(rule):
125+
parse_file = re.match(r".+/((?:\w|-)+)/profiles/(?:\w|-)+\.profile",
126+
profile_path)
127+
products.append(parse_file.group(1))
128+
# Find in controls and from controls get product
129+
for control in self.find_rule_controls(rule):
130+
for product in self.find_control_products(control):
131+
products.append(product)
132+
136133
products = sorted(products, key=lambda k: (k!="rhel8", k!="rhel7", k!="ocp4", k))
137134
return products
138135

0 commit comments

Comments
 (0)