ssg.xccdf module

A couple generic XCCDF utilities used by build_all_guides.py and build_all_remediations.py

Author: Martin Preisler <mpreisle@redhat.com>

ssg.xccdf.get_benchmark_id_title_map(input_tree)[source]

Extracts a mapping of benchmark IDs to their titles from an XML tree.

Parameters:

input_tree (xml.etree.ElementTree.ElementTree) – The XML tree containing benchmark data.

Returns:

A dictionary where the keys are benchmark IDs (str) and the values are benchmark

titles (str).

Return type:

dict

ssg.xccdf.get_profile_choices_for_input(input_tree, benchmark_id, tailoring_tree)[source]

Returns a dictionary that maps profile_ids to their respective titles.

Parameters:
  • input_tree (ElementTree) – The XML tree containing the benchmark profiles.

  • benchmark_id (str) – The ID of the benchmark to filter profiles.

  • tailoring_tree (ElementTree, optional) – An optional XML tree containing tailored profiles.

Returns:

A dictionary where keys are profile IDs and values are profile titles.

Return type:

dict

ssg.xccdf.get_profile_short_id(long_id)[source]

Shortens the given profile ID if it matches the XCCDF 1.2 long ID format.

Parameters:

long_id (str) – The long profile ID to be shortened.

Returns:

The shortened profile ID if the long ID matches the XCCDF 1.2 format, otherwise

returns the original long ID.

Return type:

str

ssg.xccdf.scrape_benchmarks(root, namespace, dest)[source]

Add all benchmark elements in root to dest list.

This function searches for all elements with the tag ‘Benchmark’ within the given XML root element, using the specified namespace. It then adds these elements to the destination list ‘dest’ along with their namespace. If the root element itself is a ‘Benchmark’, it is also added to the list.

Parameters:
  • root (xml.etree.ElementTree.Element) – The root XML element to search within.

  • namespace (str) – The XML namespace to use when searching for ‘Benchmark’ elements.

  • dest (list) – The list to which found ‘Benchmark’ elements and their namespace will be added.

Returns:

None