ComplianceAsCode/content

View on GitHub

Showing 238 of 1,093 total issues

Function preprocess has a Cognitive Complexity of 17 (exceeds 7 allowed). Consider refactoring.
Open

def preprocess(data, lang):
data["sysctlid"] = ssg.utils.escape_id(data["sysctlvar"])
if not data.get("sysctlval"):
data["sysctlval"] = ""
if data["sysctlid"].find("ipv6") >= 0:
Severity: Minor
Found in shared/templates/sysctl/template.py - About 1 hr to fix

Function preprocess has a Cognitive Complexity of 17 (exceeds 7 allowed). Consider refactoring.
Open

def preprocess(data, lang):
# Default value of default_is_enabled is false;
# When variable_name is set, this option is disabled.
# It is not easy to check if the value of an XCCDF Value is the default in a template.
data["default_is_enabled"] = parse_template_boolean_value(data, parameter="default_is_enabled", default_value=False)
Severity: Minor
Found in shared/templates/sudo_defaults_option/template.py - About 1 hr to fix

Function handle_remediations has a Cognitive Complexity of 17 (exceeds 7 allowed). Consider refactoring.
Open

def handle_remediations(product_list, product_yamls, rule_obj):
rule_dir = rule_obj['dir']
 
rule_remediations = {}
r_products = defaultdict(set)
Severity: Minor
Found in utils/rule_dir_json.py - About 1 hr to fix

Function preprocess has a Cognitive Complexity of 17 (exceeds 7 allowed). Consider refactoring.
Open

def preprocess(data, lang):
data["zero_comparison_operation"] = data.get("zero_comparison_operation", None)
 
if "greater" in data["operation"]:
if data["zero_comparison_operation"]:
Severity: Minor
Found in shared/templates/accounts_password/template.py - About 1 hr to fix

Function main has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

def main():
parser = argparse.ArgumentParser(
prog="add_kubernetes_rule.py",
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent(PROG_DESC))
Severity: Minor
Found in utils/add_kubernetes_rule.py - About 1 hr to fix

    Function find_section_lines has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
    Open

    def find_section_lines(file_contents, sec):
    """
    Parses the given file_contents as YAML to find the section with the given identifier.
     
    Note that this does not call into the yaml library and thus correctly handles Jinja macros at
    Severity: Minor
    Found in ssg/rule_yaml.py - About 1 hr to fix

    Function handle_control has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
    Open

    def handle_control(product: str, control: ssg.controls.Control, env_yaml: ssg.environment,
    rule_json: dict, srgs: dict, used_rules: list, root_path: str,
    prefer_controls: bool) -> list:
    if len(control.selections) > 0 and use_rule_content(control, prefer_controls):
    rows = list()
    Severity: Minor
    Found in utils/create_srg_export.py - About 1 hr to fix

    Function main has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
    Open

    def main():
    args = parse_args()
     
    disa_xccdftree = ET.parse(args.disa_xccdf_filename)
     
     
    Severity: Minor
    Found in utils/create-stig-overlay.py - About 1 hr to fix

    Function normalize_passed_arguments has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
    Open

    def normalize_passed_arguments(options):
    targets = []
    for target in options.target:
    if ',' in target:
    targets.extend(target.split(","))
    Severity: Minor
    Found in tests/automatus.py - About 1 hr to fix

    Function find_section_lines has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
    Open

    def find_section_lines(file_contents, sec):
    # Hack to find a global key ("section"/sec) in a YAML-like file.
    # All indented lines until the next global key are included in the range.
    # For example:
    #
    Severity: Minor
    Found in utils/fix_rules.py - About 1 hr to fix

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

    def expand_xccdf_subs(fix, remediation_type):
    """Expand the respective populate keywords of each
    remediation type with an <xccdf:sub> element
     
    This routine translates any instance of the '`type`-populate' keyword in
    Severity: Minor
    Found in ssg/build_remediations.py - About 1 hr to fix

    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 _subs has a Cognitive Complexity of 15 (exceeds 7 allowed). Consider refactoring.
    Open

    def _subs(self, substitutions, default, simplify):
    """
    Return an expression where all subterms equal to a key expression are
    substituted by the corresponding value expression using a mapping of:
    {expr->expr to substitute.}
    Severity: Minor
    Found in ssg/ext/boolean/boolean.py - About 1 hr to fix

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

    def _parse_parameters(self):
    """Parse parameters from script header"""
    params = {
    'profiles': [],
    'templates': [],
    Severity: Minor
    Found in tests/ssg_test_suite/rule.py - About 1 hr to fix

    Function get_platform_rules has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
    Open

    def get_platform_rules(product, json_path, resolved_rules_dir, build_root):
    platform_rules = list()
    if resolved_rules_dir:
    rules_path = os.path.join(build_root, product, 'rules')
    for file in os.listdir(rules_path):
    Severity: Minor
    Found in utils/create_scap_delta_tailoring.py - About 1 hr to fix

    Function inject_package_facts_task has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
    Open

    def inject_package_facts_task(self, parsed_snippet):
    """ Injects a package_facts task only if
    the snippet has a task with a when clause with ansible_facts.packages,
    and the snippet doesn't already have a package_facts task
    """
    Severity: Minor
    Found in ssg/build_remediations.py - About 1 hr to fix

    Function preprocess has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
    Open

    def preprocess(data, lang):
    ensure_file_paths_and_file_regexes_are_correctly_defined(data)
     
    data["allow_stricter_permissions"] = parse_template_boolean_value(data, parameter="allow_stricter_permissions", default_value=True)
     
     
    Severity: Minor
    Found in shared/templates/file_permissions/template.py - About 1 hr to fix

    Function _get_rules_to_test has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
    Open

    def _get_rules_to_test(self):
    """
    Returns:
    List of named tuples Rule having these fields:
    directory -- absolute path to the rule "tests" subdirectory
    Severity: Minor
    Found in tests/ssg_test_suite/rule.py - About 1 hr to fix

    Function remove_section_keys has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
    Open

    def remove_section_keys(file_contents, yaml_contents, section, removed_keys):
    # Remove a series of keys from a section. Refuses to operate if there is more
    # than one instance of the section. If the section is empty (because all keys
    # are removed), then the section is also removed. Otherwise, only matching keys
    # are removed. Note that all instances of the keys will be removed, if it appears
    Severity: Minor
    Found in utils/fix_rules.py - About 1 hr to fix

    Function run_stage has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
    Open

    def run_stage(self, stage):
    self.stage = stage
     
    self._make_verbose_path()
    self._make_report_path()
    Severity: Minor
    Found in tests/ssg_test_suite/oscap.py - About 1 hr to fix
    Severity
    Category
    Status
    Source
    Language