diff --git a/build-scripts/build_xccdf.py b/build-scripts/build_xccdf.py index 89a71da8761a..00dd5e4cc0bd 100644 --- a/build-scripts/build_xccdf.py +++ b/build-scripts/build_xccdf.py @@ -6,7 +6,7 @@ import os import os.path from collections import namedtuple - +import re import ssg.build_yaml import ssg.utils @@ -114,12 +114,22 @@ def get_linked_xccdf(loader, xccdftree, args): return oval_linker, xccdftree +def get_variables_from_go_templating(rule, var_ids): + go_templating_pattern = re.compile(r"{{(.*?)}}") + go_templating_var_pattern = re.compile(r"\.([a-zA-Z0-9_]+)") + for ele in rule.itertext(): + for match in go_templating_pattern.finditer(ele): + for var in go_templating_var_pattern.finditer(match.group(1)): + var_ids.add(var.group(1)) + + def get_rules_with_variables(xccdftree): rules = xccdftree.findall(".//{%s}Rule" % ssg.constants.XCCDF12_NS) out_var_ids = {} + go_templating_pattern = re.compile(r"{{(.*?)}}") + go_templating_var_pattern = re.compile(r"\.([a-zA-Z0-9_]+)") for rule in rules: var_ids = set() - check_export_els = rule.findall(".//{%s}check-export" % ssg.constants.XCCDF12_NS) for check_export_el in check_export_els: var_ids.add( check_export_el.get("value-id").replace("xccdf_org.ssgproject.content_value_", "") @@ -129,6 +139,7 @@ def get_rules_with_variables(xccdftree): var_ids.add( sub_el.get("idref").replace("xccdf_org.ssgproject.content_value_", "") ) + get_variables_from_go_templating(rule, var_ids) out_var_ids[ rule.get("id").replace("xccdf_org.ssgproject.content_rule_", "") ] = var_ids