File build_yaml.py
has 2854 lines of code (exceeds 400 allowed). Consider refactoring.
"""
Common functions for building YAML in SSG.
Also contains definitions of basic classes like Rule, Group, Value and Platform.
"""
Rule
has 37 functions (exceeds 20 allowed). Consider refactoring.
class Rule(XCCDFEntity, Templatable):
"""
Represents an XCCDF Rule entity with various attributes and methods for handling rule data,
validation, and conversion.
Benchmark
has 27 functions (exceeds 20 allowed). Consider refactoring.
class Benchmark(XCCDFEntity):
"""
Represents an XCCDF Benchmark entity with various attributes and methods to manipulate and
represent the benchmark data.
Function add_reference_elements
has a Cognitive Complexity of 18 (exceeds 7 allowed). Consider refactoring.
def add_reference_elements(element, references, ref_uri_dict):
"""
Adds reference elements to an XML element based on provided references and their
corresponding URIs.
Function _collect_items_to_load
has a Cognitive Complexity of 18 (exceeds 7 allowed). Consider refactoring.
def _collect_items_to_load(self, guide_directory):
"""
Collects and categorizes items from the specified guide directory.
This method iterates through the items in the given directory and sorts them into
Cyclomatic complexity is too high in method _collect_items_to_load. (11)
def _collect_items_to_load(self, guide_directory):
"""
Collects and categorizes items from the specified guide directory.
This method iterates through the items in the given directory and sorts them into
Cyclomatic complexity is too high in method process_input_dict. (11)
@classmethod
def process_input_dict(cls, input_contents, env_yaml, product_cpes=None):
"""
Processes the input dictionary and updates it with additional data.
Function validate_identifiers
has a Cognitive Complexity of 15 (exceeds 7 allowed). Consider refactoring.
def validate_identifiers(self, yaml_file):
"""
Validates the identifiers in the given YAML file.
Args:
Function validate_references
has a Cognitive Complexity of 12 (exceeds 7 allowed). Consider refactoring.
def validate_references(self, yaml_file):
"""
Validates the references section of a YAML file.
Args:
Function load_entities
has a Cognitive Complexity of 12 (exceeds 7 allowed). Consider refactoring.
def load_entities(self, rules_by_id, values_by_id, groups_by_id):
"""
Load entities into the current object's rules, values, and groups attributes.
This method updates the current object's `rules`, `values`, and `groups` attributes with
Function add_profiles_from_dir
has a Cognitive Complexity of 11 (exceeds 7 allowed). Consider refactoring.
def add_profiles_from_dir(self, dir_, env_yaml, product_cpes):
"""
Adds profiles from the specified directory to the current instance.
This method scans the given directory for files with the '.profile' extension, attempts to
Function load_entities
has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
def load_entities(self, rules_by_id, values_by_id, groups_by_id):
"""
Load entities into the current object from provided dictionaries if they are not already set.
Args:
Function reorder_according_to_ordering
has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
def reorder_according_to_ordering(unordered, ordering, regex=None):
"""
Reorders a list of items according to a specified ordering.
Args:
Function process_input_dict
has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
def process_input_dict(cls, input_contents, env_yaml, product_cpes=None):
"""
Processes the input dictionary and updates it with additional data.
Args:
Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.
def add_reference_elements(element, references, ref_uri_dict):
Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.
def _collect_items_to_load(self, guide_directory):
Similar blocks of code found in 2 locations. Consider refactoring.
if data["operator"] not in possible_operators:
raise ValueError(
"Found an invalid operator value '%s'. "
"Expected one of: %s"
% (data["operator"], ", ".join(possible_operators))
Similar blocks of code found in 3 locations. Consider refactoring.
if data["rules"]:
rule_ids = data["rules"]
data["rules"] = {rid: None for rid in rule_ids}
Similar blocks of code found in 5 locations. Consider refactoring.
for gid, val in self.groups.items():
if not val:
self.groups[gid] = groups_by_id[gid]
Similar blocks of code found in 3 locations. Consider refactoring.
if data["values"]:
value_ids = data["values"]
data["values"] = {vid: None for vid in value_ids}
Similar blocks of code found in 5 locations. Consider refactoring.
for vid, val in self.values.items():
if not val:
self.values[vid] = values_by_id[vid]
Similar blocks of code found in 3 locations. Consider refactoring.
if data["groups"]:
group_ids = data["groups"]
data["groups"] = {gid: None for gid in group_ids}
Similar blocks of code found in 5 locations. Consider refactoring.
for rid, val in self.rules.items():
if not val:
self.rules[rid] = rules_by_id[rid]
Similar blocks of code found in 5 locations. Consider refactoring.
for vid, val in self.values.items():
if not val:
self.values[vid] = values_by_id[vid]
Similar blocks of code found in 5 locations. Consider refactoring.
for rid, val in self.rules.items():
if not val:
self.rules[rid] = rules_by_id[rid]
Similar blocks of code found in 2 locations. Consider refactoring.
if isinstance(self.sce_metadata['check-import'], str):
self.sce_metadata['check-import'] = [self.sce_metadata['check-import']]
Similar blocks of code found in 2 locations. Consider refactoring.
if isinstance(self.sce_metadata['check-export'], str):
self.sce_metadata['check-export'] = [self.sce_metadata['check-export']]
Similar blocks of code found in 2 locations. Consider refactoring.
try:
new_items = make_items_product_specific(
dic, product_suffix, allow_overwrites)
except ValueError as exc:
msg = (
Similar blocks of code found in 2 locations. Consider refactoring.
for title, uri in ref_uri_dict.items():
reference = ET.SubElement(benchmark_el, "{%s}reference" % XCCDF12_NS)
reference.set("href", uri)
reference.text = title
Similar blocks of code found in 3 locations. Consider refactoring.
def add_value(self, value):
"""
Adds a value to the values dictionary if the value is not None.
Args:
Similar blocks of code found in 3 locations. Consider refactoring.
def add_value(self, value):
"""
Adds a value to the values dictionary if the value is not None.
Args:
Similar blocks of code found in 3 locations. Consider refactoring.
def add_rule(self, rule):
"""
Adds a rule to the rules dictionary.
Args:
Similar blocks of code found in 2 locations. Consider refactoring.
for entry in self.sce_metadata['check-import']:
check_import = ET.SubElement(
sce_check, '{%s}check-import' % XCCDF12_NS)
check_import.set('import-name', entry)
check_import.text = None
Similar blocks of code found in 2 locations. Consider refactoring.
rules = set(filter(lambda id_, ids=rule_ids_list: id_ not in ids, self.rules.keys()))
Similar blocks of code found in 2 locations. Consider refactoring.
for cpe_platform_name in sorted(self.cpe_platform_names):
platform_el = ET.SubElement(rule, "{%s}platform" % XCCDF12_NS)
platform_el.set("idref", "#"+cpe_platform_name)
Similar blocks of code found in 2 locations. Consider refactoring.
variables = set(
filter(lambda id_, ids=variables_ids_list: id_ not in ids, self.values.keys())
Similar blocks of code found in 2 locations. Consider refactoring.
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)
Similar blocks of code found in 2 locations. Consider refactoring.
try:
self.make_refs_and_identifiers_product_specific(product)
self.make_template_product_specific(product)
except Exception as exc:
msg = (
Similar blocks of code found in 4 locations. Consider refactoring.
add_nondata_subelements(
rule, "conflicts", "idref",
list(map(lambda x: OSCAP_RULE + x, self.conflicts)))
Similar blocks of code found in 4 locations. Consider refactoring.
add_nondata_subelements(
rule, "requires", "idref",
list(map(lambda x: OSCAP_RULE + x, self.requires)))
Similar blocks of code found in 4 locations. Consider refactoring.
add_nondata_subelements(
group, "conflicts", "idref",
list(map(lambda x: OSCAP_GROUP + x, self.conflicts)))
Similar blocks of code found in 4 locations. Consider refactoring.
add_nondata_subelements(
group, "requires", "idref",
list(map(lambda x: OSCAP_GROUP + x, self.requires)))
Similar blocks of code found in 5 locations. Consider refactoring.
except Exception as exc:
msg = ("Error building profile from '{fname}': '{error}'"
.format(fname=dir_item_path, error=str(exc)))
raise RuntimeError(msg)
Line too long (100 > 99 characters)
- If a profile file is incomplete or an error occurs during its creation, it is skipped.
Line too long (119 > 99 characters)
ignore_single_rule_profiles (bool): All profiles that contain "single_rule_profile: true" will be skipping.
Line too long (103 > 99 characters)
- Specific group orders are maintained to avoid conflicts and ensure proper rule execution.
Line too long (108 > 99 characters)
raise ValueError("CCE Identifier format must be valid: invalid format '%s' for CEE '%s'"
Line too long (118 > 99 characters)
- Directories identified as rule directories are processed and their YAML files are added to `rule_files`.
Line too long (104 > 99 characters)
cls (type): Class type that has a `from_yaml` method to create an instance from a YAML file.
Line too long (104 > 99 characters)
If the conversion to XML results in a None root, the method returns without writing to the file.
Line too long (100 > 99 characters)
product_cpes (ProductCPEs): The product CPEs to use for parsing and resolving CPE items.
Line too long (100 > 99 characters)
Returns None if OCIL is turned off or no rules are found.
Line too long (101 > 99 characters)
element (xml.etree.ElementTree.Element): The XML element to which the metadata will be added.
Line too long (105 > 99 characters)
Loads entities from a list of YAML files and stores them in a destination dictionary by their ID.
Line too long (110 > 99 characters)
env_yaml (dict, optional): An optional parameter that can be used to customize the XML generation.
Line too long (100 > 99 characters)
Remove rules from the current object whose IDs are not listed in the provided rule_ids_list.
Line too long (108 > 99 characters)
root (xml.etree.ElementTree.Element): The root XML element to which rule elements will be added.
Line too long (116 > 99 characters)
raise ValueError("CCE Identifier value is not a valid checksum: invalid value '%s' for CEE '%s'"
Line too long (101 > 99 characters)
tuple: A tuple containing the profile ID (str) and the corresponding benchmark XML (str).
Line too long (106 > 99 characters)
childs (dict): A dictionary where the key is the child's ID and the value is the child object.
Line too long (101 > 99 characters)
Load entities into the current object from provided dictionaries if they are not already set.
Line too long (109 > 99 characters)
env_yaml (dict, optional): An optional dictionary containing environment variables for the rules.
Line too long (112 > 99 characters)
root (xml.etree.ElementTree.Element): The root XML element to which the OCIL elements will be added.
Line too long (102 > 99 characters)
Platform: The existing platform if it was already defined, otherwise the newly added platform.
Line too long (104 > 99 characters)
rules_and_variables_dict (dict): A dictionary mapping rule identifiers to sets of variables.
Line too long (101 > 99 characters)
- variables (set): A set of variable IDs that are not in the provided variables_ids_list.
Line too long (109 > 99 characters)
Saves all entities (rules, groups, values, platforms, and cpe_items) to the specified base directory.
Line too long (104 > 99 characters)
ValueError: If the operator in the input data is not one of the expected possible operators.
Line too long (100 > 99 characters)
Adds a child object to the given dictionary of children and updates its inherited platforms.
Line too long (103 > 99 characters)
rules (list): A list of rule objects. Each rule object should have 'ocil' and 'ocil_clause'
Line too long (100 > 99 characters)
env_yaml (dict, optional): An optional environment YAML configuration that may be passed
Line too long (109 > 99 characters)
components_to_not_include (dict): A dictionary containing components that should not be included.
Line too long (100 > 99 characters)
priority_order = ["enable_authselect", "installed", "install_smartcard_packages", "removed",
Line too long (105 > 99 characters)
Determines and returns the appropriate parent element for SCE checks within a given rule element.
Line too long (100 > 99 characters)
ValueError: If both a .benchmark file and a .group file are found in the same directory.
There are no issues that match your filters.