Skip to content

Commit

Permalink
Rework Group xml generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Honny1 committed Feb 21, 2024
1 parent 734a000 commit 4d3d855
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions ssg/build_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,31 +578,21 @@ def represent_as_dict(self):

return yaml_contents

def to_xml_element(self, env_yaml=None):
def _create_group_xml_skeleton(self):
group = ET.Element('{%s}Group' % XCCDF12_NS)
group.set('id', OSCAP_GROUP + self.id_)
title = ET.SubElement(group, '{%s}title' % XCCDF12_NS)
title.text = self.title
add_sub_element(group, 'description', XCCDF12_NS, self.description)
add_warning_elements(group, self.warnings)
return group

# This is where references should be put if there are any
# This is where rationale should be put if there are any

def _add_cpe_platforms_xml(self, group):
for cpe_platform_name in self.cpe_platform_names:
platform_el = ET.SubElement(group, "{%s}platform" % XCCDF12_NS)
platform_el.set("idref", "#"+cpe_platform_name)

add_nondata_subelements(
group, "requires", "idref",
list(map(lambda x: OSCAP_GROUP + x, self.requires)))
add_nondata_subelements(
group, "conflicts", "idref",
list(map(lambda x: OSCAP_GROUP + x, self.conflicts)))
for _value in self.values.values():
if _value is not None:
group.append(_value.to_xml_element())

def _add_rules_xml(self, group, env_yaml):
# Rules that install or remove packages affect remediation
# of other rules.
# When packages installed/removed rules come first:
Expand All @@ -626,6 +616,7 @@ def to_xml_element(self, env_yaml=None):
if rule is not None:
group.append(rule.to_xml_element(env_yaml))

def _add_sub_groups(self, group, env_yaml):
# Add the sub groups after any current level group rules.
# As package installed/removed and service enabled/disabled rules are usuallly in
# top level group, this ensures groups that further configure a package or service
Expand Down Expand Up @@ -666,6 +657,28 @@ def to_xml_element(self, env_yaml=None):
if _group is not None:
group.append(_group.to_xml_element(env_yaml))

def to_xml_element(self, env_yaml=None):

group = self._create_group_xml_skeleton()

# This is where references should be put if there are any
# This is where rationale should be put if there are any

self._add_cpe_platforms_xml(group)

add_nondata_subelements(
group, "requires", "idref",
list(map(lambda x: OSCAP_GROUP + x, self.requires)))
add_nondata_subelements(
group, "conflicts", "idref",
list(map(lambda x: OSCAP_GROUP + x, self.conflicts)))
for _value in self.values.values():
if _value is not None:
group.append(_value.to_xml_element())

self._add_rules_xml(group, env_yaml)
self._add_sub_groups(group, env_yaml)

return group

def add_value(self, value):
Expand Down

0 comments on commit 4d3d855

Please sign in to comment.