ssg.id_translate module
Common functions for processing ID Translations in SSG
- class ssg.id_translate.IDTranslator(content_id)[source]
Bases:
objectIDTranslator is a class designed to handle the mapping of meaningful, human-readable names to IDs in the formats required by the SCAP checking systems, such as OVAL and OCIL.
- content_id
The content identifier used in generating IDs.
- Type:
str
- generate_id(tagname, name)[source]
Generates a unique identifier string based on the provided tag name and name.
- Parameters:
tagname (str) – The tag name to be used in the identifier.
name (str) – The name to be used in the identifier.
- Returns:
- A unique identifier string in the format
”<namespace_prefix>:<content_id>-<name>:<tagname_abbrev>:1”.
- Return type:
str
- translate(tree, store_defname=False)[source]
Translates the IDs of elements in an XML tree to new identifiers.
- Parameters:
tree (ElementTree.Element) – The XML tree to be processed.
store_defname (bool, optional) – If True, stores the old name in the metadata for OVAL definitions. Defaults to False.
- Returns:
The processed XML tree with updated IDs.
- Return type:
ElementTree.Element
The function iterates through each element in the provided XML tree and performs the following actions based on the element’s tag and attributes: - If the element has an “id” attribute, it generates a new ID and sets it. - If store_defname is True and the element is an OVAL definition, it stores the old ID
in the metadata.
For specific tags like “filter”, “var_ref”, and “object_reference”, it updates the text content with a new ID.
For attributes that match keys in OVALREFATTR_TO_TAG or OCILREFATTR_TO_TAG, it updates the attribute value with a new ID.
For the “test_action_ref” tag, it updates the text content with a new ID.
- translate_oval_document(oval_document, store_defname=False)[source]
Translates and validates an OVAL document.
This method translates the IDs in the given OVAL document and validates its references.
- Parameters:
oval_document – The OVAL document to be translated and validated.
store_defname (bool, optional) – If True, stores the definition name during translation. Defaults to False.
- Returns:
The translated and validated OVAL document.