ssg.entities.common module

class ssg.entities.common.SelectionHandler[source]

Bases: object

apply_selection(item)[source]
property selections
update_with(rhs)[source]
class ssg.entities.common.Templatable[source]

Bases: object

The Templatable is a mix-in sidekick for XCCDFEntity-based classes that have templates. It contains methods used by the template Builder class.

Methods get_template_context and get_template_vars are subject for overloading by XCCDFEntity subclasses that want to customize template input.

KEYS = {'template': <function Templatable.<lambda>>}
extract_configured_backend_lang(avail_langs)[source]

Returns list of languages that should be generated based on the Templatable’s template option template.backends.

get_template_context(env_yaml)[source]
get_template_name()[source]
get_template_vars(env_yaml)[source]
is_templated()[source]
make_template_product_specific(product)[source]
class ssg.entities.common.XCCDFEntity(id_)[source]

Bases: object

This class can load itself from a YAML with Jinja macros, and it can also save itself to YAML.

It is supposed to work with the content in the project, when entities are defined in the benchmark tree, and they are compiled into flat YAMLs to the build directory.

ALTERNATIVE_KEYS = {}
GENERIC_FILENAME = ''
ID_LABEL = 'id'
KEYS = {'definition_location': <function XCCDFEntity.<lambda>>, 'id_': <function XCCDFEntity.<lambda>>, 'title': <function XCCDFEntity.<lambda>>}
MANDATORY_KEYS = {}
dump_yaml(file_name, documentation_complete=True)[source]
classmethod from_yaml(yaml_file, env_yaml=None, product_cpes=None)[source]
classmethod get_instance_from_full_dict(data)[source]

Given a defining dictionary, produce an instance by treating all dict elements as attributes.

Extend this if you want tight control over the instance creation process.

classmethod parse_yaml_into_processed_dict(yaml_file, env_yaml=None, product_cpes=None)[source]

Given yaml filename and environment info, produce a dictionary that defines the instance to be created. This wraps process_input_dict() and it adds generic keys on the top:

  • id_ as the entity ID that is deduced either from the file name, or from the parent directory name.

  • definition_location is the original location where the entity got defined.

classmethod process_input_dict(input_contents, env_yaml, product_cpes=None)[source]

Take the contents of the definition as a dictionary, and add defaults or raise errors if a required member is not present.

Extend this if you want to add, remove or alter the result that will constitute the new instance.

represent_as_dict()[source]

Produce a dict representation of the class.

Extend this method if you need the representation to be different from the object.

to_file(file_name)[source]
to_xml_element()[source]
ssg.entities.common.add_sub_element(parent, tag, ns, data)[source]

Creates a new child element under parent with tag tag, and sets data as the content under the tag. In particular, data is a string to be parsed as an XML tree, allowing sub-elements of children to be added.

If data should not be parsed as an XML tree, either escape the contents before passing into this function, or use ElementTree.SubElement().

Returns the newly created subelement of type tag.

ssg.entities.common.derive_id_from_file_name(filename)[source]
ssg.entities.common.dump_yaml_preferably_in_original_order(dictionary, file_object)[source]
ssg.entities.common.extract_reference_from_product_specific_label(items_dict, full_label, value, allow_overwrites)[source]
ssg.entities.common.make_items_product_specific(items_dict, product_suffix, allow_overwrites=False)[source]

Function will normalize dictionary values for a specific product, by either removing product qualifier from the key (reference@product: value -> reference: value), or by dropping irrelevant entries (reference@other_product: value).

Qualified entries always take precedence over generic ones.

In case when allow_overwrites is set to False even qualified entry won’t be allowed to replace generic one and Exception will be thrown.

Parameters:
  • items_dict – Input dictionary.

  • product_suffix – The product to be normalized against.

  • allow_overwrites – Controls if the function should replace value from a non-qualified label with a qualified one.

Returns:

New, normalized dictionary.