Sorry, data for that comparison is no longer available.

ComplianceAsCode/content

View on GitHub
ssg/build_yaml.py

Summary

Maintainability
F
1 wk
Test Coverage
F
47%

Showing 75 of 75 total issues

File build_yaml.py has 2854 lines of code (exceeds 400 allowed). Consider refactoring.
Open

"""
Common functions for building YAML in SSG.
Also contains definitions of basic classes like Rule, Group, Value and Platform.
"""
 
 
Severity: Major
Found in ssg/build_yaml.py - About 1 wk to fix

    Rule has 37 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Rule(XCCDFEntity, Templatable):
    """
    Represents an XCCDF Rule entity with various attributes and methods for handling rule data,
    validation, and conversion.
     
     
    Severity: Minor
    Found in ssg/build_yaml.py - About 4 hrs to fix

      Benchmark has 27 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Benchmark(XCCDFEntity):
      """
      Represents an XCCDF Benchmark entity with various attributes and methods to manipulate and
      represent the benchmark data.
       
       
      Severity: Minor
      Found in ssg/build_yaml.py - About 3 hrs to fix

        Function add_reference_elements has a Cognitive Complexity of 18 (exceeds 7 allowed). Consider refactoring.
        Open

        def add_reference_elements(element, references, ref_uri_dict):
        """
        Adds reference elements to an XML element based on provided references and their
        corresponding URIs.
         
         
        Severity: Minor
        Found in ssg/build_yaml.py - About 2 hrs to fix

        Function _collect_items_to_load has a Cognitive Complexity of 18 (exceeds 7 allowed). Consider refactoring.
        Open

        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
        Severity: Minor
        Found in ssg/build_yaml.py - About 2 hrs to fix

        Cyclomatic complexity is too high in method _collect_items_to_load. (11)
        Open

        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
        Severity: Minor
        Found in ssg/build_yaml.py by radon

        Cyclomatic complexity is too high in method process_input_dict. (11)
        Open

        @classmethod
        def process_input_dict(cls, input_contents, env_yaml, product_cpes=None):
        """
        Processes the input dictionary and updates it with additional data.
         
         
        Severity: Minor
        Found in ssg/build_yaml.py by radon

        Function validate_identifiers has a Cognitive Complexity of 15 (exceeds 7 allowed). Consider refactoring.
        Open

        def validate_identifiers(self, yaml_file):
        """
        Validates the identifiers in the given YAML file.
         
        Args:
        Severity: Minor
        Found in ssg/build_yaml.py - About 1 hr to fix

        Function validate_references has a Cognitive Complexity of 12 (exceeds 7 allowed). Consider refactoring.
        Open

        def validate_references(self, yaml_file):
        """
        Validates the references section of a YAML file.
         
        Args:
        Severity: Minor
        Found in ssg/build_yaml.py - About 1 hr to fix

        Function load_entities has a Cognitive Complexity of 12 (exceeds 7 allowed). Consider refactoring.
        Open

        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
        Severity: Minor
        Found in ssg/build_yaml.py - About 1 hr to fix

        Function add_profiles_from_dir has a Cognitive Complexity of 11 (exceeds 7 allowed). Consider refactoring.
        Open

        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
        Severity: Minor
        Found in ssg/build_yaml.py - About 55 mins to fix

        Function load_entities has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
        Open

        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:
        Severity: Minor
        Found in ssg/build_yaml.py - About 35 mins to fix

        Function reorder_according_to_ordering has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
        Open

        def reorder_according_to_ordering(unordered, ordering, regex=None):
        """
        Reorders a list of items according to a specified ordering.
         
        Args:
        Severity: Minor
        Found in ssg/build_yaml.py - About 25 mins to fix

        Function process_input_dict has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
        Open

        def process_input_dict(cls, input_contents, env_yaml, product_cpes=None):
        """
        Processes the input dictionary and updates it with additional data.
         
        Args:
        Severity: Minor
        Found in ssg/build_yaml.py - About 25 mins to fix

        Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.
        Open

        def add_reference_elements(element, references, ref_uri_dict):
        Severity: Critical
        Found in ssg/build_yaml.py by sonar-python

        Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.
        Open

        def _collect_items_to_load(self, guide_directory):
        Severity: Critical
        Found in ssg/build_yaml.py by sonar-python

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        if data["operator"] not in possible_operators:
        raise ValueError(
        "Found an invalid operator value '%s'. "
        "Expected one of: %s"
        % (data["operator"], ", ".join(possible_operators))
        Severity: Major
        Found in ssg/build_yaml.py and 1 other location - About 1 hr to fix
        ssg/build_sce.py on lines 82..86

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

        if data["rules"]:
        rule_ids = data["rules"]
        data["rules"] = {rid: None for rid in rule_ids}
        Severity: Major
        Found in ssg/build_yaml.py and 2 other locations - About 1 hr to fix
        ssg/build_yaml.py on lines 1116..1118
        ssg/build_yaml.py on lines 1120..1122

        Similar blocks of code found in 5 locations. Consider refactoring.
        Open

        for gid, val in self.groups.items():
        if not val:
        self.groups[gid] = groups_by_id[gid]
        Severity: Major
        Found in ssg/build_yaml.py and 4 other locations - About 1 hr to fix
        ssg/build_yaml.py on lines 453..455
        ssg/build_yaml.py on lines 457..459
        ssg/build_yaml.py on lines 1158..1160
        ssg/build_yaml.py on lines 1162..1164

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

        if data["values"]:
        value_ids = data["values"]
        data["values"] = {vid: None for vid in value_ids}
        Severity: Major
        Found in ssg/build_yaml.py and 2 other locations - About 1 hr to fix
        ssg/build_yaml.py on lines 1112..1114
        ssg/build_yaml.py on lines 1116..1118

        Similar blocks of code found in 5 locations. Consider refactoring.
        Open

        for vid, val in self.values.items():
        if not val:
        self.values[vid] = values_by_id[vid]
        Severity: Major
        Found in ssg/build_yaml.py and 4 other locations - About 1 hr to fix
        ssg/build_yaml.py on lines 453..455
        ssg/build_yaml.py on lines 457..459
        ssg/build_yaml.py on lines 461..463
        ssg/build_yaml.py on lines 1158..1160

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

        if data["groups"]:
        group_ids = data["groups"]
        data["groups"] = {gid: None for gid in group_ids}
        Severity: Major
        Found in ssg/build_yaml.py and 2 other locations - About 1 hr to fix
        ssg/build_yaml.py on lines 1112..1114
        ssg/build_yaml.py on lines 1120..1122

        Similar blocks of code found in 5 locations. Consider refactoring.
        Open

        for rid, val in self.rules.items():
        if not val:
        self.rules[rid] = rules_by_id[rid]
        Severity: Major
        Found in ssg/build_yaml.py and 4 other locations - About 1 hr to fix
        ssg/build_yaml.py on lines 457..459
        ssg/build_yaml.py on lines 461..463
        ssg/build_yaml.py on lines 1158..1160
        ssg/build_yaml.py on lines 1162..1164

        Similar blocks of code found in 5 locations. Consider refactoring.
        Open

        for vid, val in self.values.items():
        if not val:
        self.values[vid] = values_by_id[vid]
        Severity: Major
        Found in ssg/build_yaml.py and 4 other locations - About 1 hr to fix
        ssg/build_yaml.py on lines 453..455
        ssg/build_yaml.py on lines 461..463
        ssg/build_yaml.py on lines 1158..1160
        ssg/build_yaml.py on lines 1162..1164

        Similar blocks of code found in 5 locations. Consider refactoring.
        Open

        for rid, val in self.rules.items():
        if not val:
        self.rules[rid] = rules_by_id[rid]
        Severity: Major
        Found in ssg/build_yaml.py and 4 other locations - About 1 hr to fix
        ssg/build_yaml.py on lines 453..455
        ssg/build_yaml.py on lines 457..459
        ssg/build_yaml.py on lines 461..463
        ssg/build_yaml.py on lines 1162..1164

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        if isinstance(self.sce_metadata['check-import'], str):
        self.sce_metadata['check-import'] = [self.sce_metadata['check-import']]
        Severity: Major
        Found in ssg/build_yaml.py and 1 other location - About 1 hr to fix
        ssg/build_yaml.py on lines 2350..2351

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        if isinstance(self.sce_metadata['check-export'], str):
        self.sce_metadata['check-export'] = [self.sce_metadata['check-export']]
        Severity: Major
        Found in ssg/build_yaml.py and 1 other location - About 1 hr to fix
        ssg/build_yaml.py on lines 2324..2325

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        try:
        new_items = make_items_product_specific(
        dic, product_suffix, allow_overwrites)
        except ValueError as exc:
        msg = (
        Severity: Major
        Found in ssg/build_yaml.py and 1 other location - About 1 hr to fix
        build-scripts/collect_remediations.py on lines 114..121

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        for title, uri in ref_uri_dict.items():
        reference = ET.SubElement(benchmark_el, "{%s}reference" % XCCDF12_NS)
        reference.set("href", uri)
        reference.text = title
        Severity: Minor
        Found in ssg/build_yaml.py and 1 other location - About 50 mins to fix
        ssg/build_yaml.py on lines 2326..2330

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

        def add_value(self, value):
        """
        Adds a value to the values dictionary if the value is not None.
         
        Args:
        Severity: Major
        Found in ssg/build_yaml.py and 2 other locations - About 50 mins to fix
        ssg/build_yaml.py on lines 962..974
        ssg/build_yaml.py on lines 994..1006

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

        def add_value(self, value):
        """
        Adds a value to the values dictionary if the value is not None.
         
        Args:
        Severity: Major
        Found in ssg/build_yaml.py and 2 other locations - About 50 mins to fix
        ssg/build_yaml.py on lines 994..1006
        ssg/build_yaml.py on lines 1396..1409

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

        def add_rule(self, rule):
        """
        Adds a rule to the rules dictionary.
         
        Args:
        Severity: Major
        Found in ssg/build_yaml.py and 2 other locations - About 50 mins to fix
        ssg/build_yaml.py on lines 962..974
        ssg/build_yaml.py on lines 1396..1409

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        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
        Severity: Minor
        Found in ssg/build_yaml.py and 1 other location - About 50 mins to fix
        ssg/build_yaml.py on lines 254..257

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        rules = set(filter(lambda id_, ids=rule_ids_list: id_ not in ids, self.rules.keys()))
        Severity: Minor
        Found in ssg/build_yaml.py and 1 other location - About 45 mins to fix
        ssg/build_yaml.py on lines 1544..1545

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        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)
        Severity: Minor
        Found in ssg/build_yaml.py and 1 other location - About 45 mins to fix
        ssg/build_yaml.py on lines 1232..1234

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        variables = set(
        filter(lambda id_, ids=variables_ids_list: id_ not in ids, self.values.keys())
        Severity: Minor
        Found in ssg/build_yaml.py and 1 other location - About 45 mins to fix
        ssg/build_yaml.py on lines 1543..1543

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        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)
        Severity: Minor
        Found in ssg/build_yaml.py and 1 other location - About 45 mins to fix
        ssg/build_yaml.py on lines 2503..2505

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        try:
        self.make_refs_and_identifiers_product_specific(product)
        self.make_template_product_specific(product)
        except Exception as exc:
        msg = (
        Severity: Minor
        Found in ssg/build_yaml.py and 1 other location - About 45 mins to fix
        ssg/controls.py on lines 495..502

        Similar blocks of code found in 4 locations. Consider refactoring.
        Open

        add_nondata_subelements(
        rule, "conflicts", "idref",
        list(map(lambda x: OSCAP_RULE + x, self.conflicts)))
        Severity: Major
        Found in ssg/build_yaml.py and 3 other locations - About 35 mins to fix
        ssg/build_yaml.py on lines 1377..1379
        ssg/build_yaml.py on lines 1380..1382
        ssg/build_yaml.py on lines 2507..2509

        Similar blocks of code found in 4 locations. Consider refactoring.
        Open

        add_nondata_subelements(
        rule, "requires", "idref",
        list(map(lambda x: OSCAP_RULE + x, self.requires)))
        Severity: Major
        Found in ssg/build_yaml.py and 3 other locations - About 35 mins to fix
        ssg/build_yaml.py on lines 1377..1379
        ssg/build_yaml.py on lines 1380..1382
        ssg/build_yaml.py on lines 2510..2512

        Similar blocks of code found in 4 locations. Consider refactoring.
        Open

        add_nondata_subelements(
        group, "conflicts", "idref",
        list(map(lambda x: OSCAP_GROUP + x, self.conflicts)))
        Severity: Major
        Found in ssg/build_yaml.py and 3 other locations - About 35 mins to fix
        ssg/build_yaml.py on lines 1377..1379
        ssg/build_yaml.py on lines 2507..2509
        ssg/build_yaml.py on lines 2510..2512

        Similar blocks of code found in 4 locations. Consider refactoring.
        Open

        add_nondata_subelements(
        group, "requires", "idref",
        list(map(lambda x: OSCAP_GROUP + x, self.requires)))
        Severity: Major
        Found in ssg/build_yaml.py and 3 other locations - About 35 mins to fix
        ssg/build_yaml.py on lines 1380..1382
        ssg/build_yaml.py on lines 2507..2509
        ssg/build_yaml.py on lines 2510..2512

        Similar blocks of code found in 5 locations. Consider refactoring.
        Open

        except Exception as exc:
        msg = ("Error building profile from '{fname}': '{error}'"
        .format(fname=dir_item_path, error=str(exc)))
        raise RuntimeError(msg)
        Severity: Major
        Found in ssg/build_yaml.py and 4 other locations - About 35 mins to fix
        ssg/entities/common.py on lines 243..249
        ssg/jinja.py on lines 72..77
        utils/fix_rules.py on lines 489..493
        utils/fix_rules.py on lines 573..579

        Line too long (100 > 99 characters)
        Open

        - If a profile file is incomplete or an error occurs during its creation, it is skipped.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (119 > 99 characters)
        Open

        ignore_single_rule_profiles (bool): All profiles that contain "single_rule_profile: true" will be skipping.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (103 > 99 characters)
        Open

        - Specific group orders are maintained to avoid conflicts and ensure proper rule execution.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (108 > 99 characters)
        Open

        raise ValueError("CCE Identifier format must be valid: invalid format '%s' for CEE '%s'"
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (118 > 99 characters)
        Open

        - Directories identified as rule directories are processed and their YAML files are added to `rule_files`.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (104 > 99 characters)
        Open

        cls (type): Class type that has a `from_yaml` method to create an instance from a YAML file.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (104 > 99 characters)
        Open

        If the conversion to XML results in a None root, the method returns without writing to the file.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (100 > 99 characters)
        Open

        product_cpes (ProductCPEs): The product CPEs to use for parsing and resolving CPE items.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (100 > 99 characters)
        Open

        Returns None if OCIL is turned off or no rules are found.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (101 > 99 characters)
        Open

        element (xml.etree.ElementTree.Element): The XML element to which the metadata will be added.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (105 > 99 characters)
        Open

        Loads entities from a list of YAML files and stores them in a destination dictionary by their ID.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (110 > 99 characters)
        Open

        env_yaml (dict, optional): An optional parameter that can be used to customize the XML generation.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (100 > 99 characters)
        Open

        Remove rules from the current object whose IDs are not listed in the provided rule_ids_list.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (108 > 99 characters)
        Open

        root (xml.etree.ElementTree.Element): The root XML element to which rule elements will be added.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (116 > 99 characters)
        Open

        raise ValueError("CCE Identifier value is not a valid checksum: invalid value '%s' for CEE '%s'"
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (101 > 99 characters)
        Open

        tuple: A tuple containing the profile ID (str) and the corresponding benchmark XML (str).
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (106 > 99 characters)
        Open

        childs (dict): A dictionary where the key is the child's ID and the value is the child object.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (101 > 99 characters)
        Open

        Load entities into the current object from provided dictionaries if they are not already set.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (109 > 99 characters)
        Open

        env_yaml (dict, optional): An optional dictionary containing environment variables for the rules.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (112 > 99 characters)
        Open

        root (xml.etree.ElementTree.Element): The root XML element to which the OCIL elements will be added.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (102 > 99 characters)
        Open

        Platform: The existing platform if it was already defined, otherwise the newly added platform.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (104 > 99 characters)
        Open

        rules_and_variables_dict (dict): A dictionary mapping rule identifiers to sets of variables.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (101 > 99 characters)
        Open

        - variables (set): A set of variable IDs that are not in the provided variables_ids_list.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (109 > 99 characters)
        Open

        Saves all entities (rules, groups, values, platforms, and cpe_items) to the specified base directory.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (104 > 99 characters)
        Open

        ValueError: If the operator in the input data is not one of the expected possible operators.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (100 > 99 characters)
        Open

        Adds a child object to the given dictionary of children and updates its inherited platforms.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (103 > 99 characters)
        Open

        rules (list): A list of rule objects. Each rule object should have 'ocil' and 'ocil_clause'
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (100 > 99 characters)
        Open

        env_yaml (dict, optional): An optional environment YAML configuration that may be passed
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (109 > 99 characters)
        Open

        components_to_not_include (dict): A dictionary containing components that should not be included.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (100 > 99 characters)
        Open

        priority_order = ["enable_authselect", "installed", "install_smartcard_packages", "removed",
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (105 > 99 characters)
        Open

        Determines and returns the appropriate parent element for SCE checks within a given rule element.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8

        Line too long (100 > 99 characters)
        Open

        ValueError: If both a .benchmark file and a .group file are found in the same directory.
        Severity: Minor
        Found in ssg/build_yaml.py by pep8
        Category
        Status