ssg.checks module

Common functions for processing Checks in SSG

ssg.checks.get_content_ref_if_exists_and_not_remote(check)[source]

Given an OVAL check element, examine the xccdf_ns:check-content-ref.

If the check-content-ref element exists and it isn’t remote, return it.

Parameters:

check (Element) – An OVAL check element to be examined.

Returns:

The check-content-ref element if it exists and is not remote, otherwise None.

Return type:

Element or None

See also

is_content_href_remote: Function to determine if the content reference is remote.

ssg.checks.get_oval_contents(rule_obj, oval_id)[source]

Returns the tuple (path, contents) of the check described by the given oval_id or product.

Parameters:
  • rule_obj (object) – The rule object containing the OVAL definitions.

  • oval_id (str) – The identifier of the OVAL check.

Returns:

A tuple containing the path to the OVAL file and its contents.

Return type:

tuple

ssg.checks.get_oval_path(rule_obj, oval_id)[source]

Returns the full path to the OVAL check file for the given rule object and OVAL ID.

Parameters:
  • rule_obj (dict) – A dictionary containing rule information. It must include the keys ‘dir’, ‘id’, and ‘ovals’.

  • oval_id (str) – A string representing the ID of the OVAL check file. If it does not end with “.xml”, the extension will be appended.

Returns:

The full path to the OVAL check file.

Return type:

str

Raises:

ValueError – If the rule_obj is malformed or if the oval_id is unknown for the given rule.

ssg.checks.is_content_href_remote(check_content_ref)[source]

Given an OVAL check-content-ref element, examine the ‘href’ attribute.

Parameters:

check_content_ref (Element) – An XML element representing the OVAL check-content-ref.

Returns:

True if the ‘href’ attribute starts with ‘http://’ or ‘https://’, otherwise False.

Return type:

bool

Raises:

RuntimeError – If the ‘href’ attribute does not exist in the check_content_ref element.

ssg.checks.set_applicable_platforms(oval_contents, new_platforms)[source]

Modifies the given OVAL contents to update the platforms to the new platforms.

Parameters:
  • oval_contents (list of str) – The original OVAL content lines.

  • new_platforms (list of str) – The new platforms to be set in the OVAL content.

Returns:

The modified OVAL content lines with updated platforms.

Return type:

list of str