ComplianceAsCode/content

View on GitHub

Showing 231 of 1,039 total issues

Function ssg_xccdf_stigid_mapping has a Cognitive Complexity of 21 (exceeds 7 allowed). Consider refactoring.
Open

def ssg_xccdf_stigid_mapping(ssgtree):
    xccdf_ns = ssg.xml.determine_xccdf_tree_namespace(ssgtree)
    xccdftostig_idmapping = {}

    for rule in ssgtree.findall(".//{%s}Rule" % xccdf_ns):
Severity: Minor
Found in utils/create-stig-overlay.py - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

def main():
    args = parse_args()

    product_allowlist = set(PRODUCT_ALLOWLIST)
    profile_allowlist = set(PROFILE_ALLOWLIST)
Severity: Minor
Found in utils/ansible_playbook_to_role.py - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

def main():
    parser = argparse.ArgumentParser(
        description="Test Jinja macros that Generate OVAL")
    parser.add_argument(
        "--verbose", action="store_true", default=False,
Severity: Major
Found in tests/test_macros_oval.py - About 2 hrs to fix

    PlaybookToRoleConverter has 23 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class PlaybookToRoleConverter():
        PRODUCED_FILES = ('defaults/main.yml', 'meta/main.yml', 'tasks/main.yml', 'vars/main.yml',
                          'README.md')
    
        def __init__(self, local_playbook_filename):
    Severity: Minor
    Found in utils/ansible_playbook_to_role.py - About 2 hrs to fix

      GenericRunner has 23 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class GenericRunner(object):
          def __init__(self, environment, profile, datastream, benchmark_id):
              self.environment = environment
              self.profile = profile
              self.datastream = datastream
      Severity: Minor
      Found in tests/ssg_test_suite/oscap.py - About 2 hrs to fix

        Function clusterTestFunc has a Cognitive Complexity of 20 (exceeds 7 allowed). Consider refactoring.
        Open

        def clusterTestFunc(args):
        
            print('* Testing rule %s in-cluster' % args.rule)
        
            findout = subprocess.getoutput(
        Severity: Minor
        Found in utils/add_kubernetes_rule.py - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

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

        def main():
            args = parse_args()
        
            linux_products, other_products = ssg.products.get_all(args.root)
            all_products = linux_products.union(other_products)
        Severity: Minor
        Found in utils/rule_dir_json.py - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        File add_kubernetes_rule.py has 412 lines of code (exceeds 400 allowed). Consider refactoring.
        Open

        #!/usr/bin/python3
        
        import argparse
        import subprocess
        import sys
        Severity: Minor
        Found in utils/add_kubernetes_rule.py - About 2 hrs to fix

          Function tokenize has a Cognitive Complexity of 19 (exceeds 7 allowed). Consider refactoring.
          Open

              def tokenize(self, expr):
                  """
                  Return an iterable of 3-tuple describing each token given an expression
                  unicode string.
          
          
          Severity: Minor
          Found in ssg/ext/boolean/boolean.py - About 2 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function get_rule_to_stig_dict has a Cognitive Complexity of 19 (exceeds 7 allowed). Consider refactoring.
          Open

          def get_rule_to_stig_dict(xml: ElementTree.ElementTree, benchmark_creator: str) -> dict:
              rules = dict()
              for group in xml.findall(f'{XCCDF12}:Group', PREFIX_TO_NS):
                  for sub_groups in group.findall(f'{XCCDF12}:Group', PREFIX_TO_NS):
                      rules.update(get_rule_to_stig_dict(ElementTree.ElementTree(sub_groups),
          Severity: Minor
          Found in utils/compare_results.py - About 2 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function get_profile_choices_for_input has a Cognitive Complexity of 19 (exceeds 7 allowed). Consider refactoring.
          Open

          def get_profile_choices_for_input(input_tree, benchmark_id, tailoring_tree):
              """
              Returns a dictionary that maps profile_ids to their respective titles.
          
              Args:
          Severity: Minor
          Found in ssg/xccdf.py - About 2 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function _get_implied_properties has a Cognitive Complexity of 19 (exceeds 7 allowed). Consider refactoring.
          Open

          def _get_implied_properties(existing_properties):
              """
              Generate a dictionary of properties with default values for missing keys.
          
              This function takes an existing dictionary of properties and adds default values for certain
          Severity: Minor
          Found in ssg/products.py - About 2 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          TestEnv has 21 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class TestEnv(object):
              def __init__(self, scanning_mode):
                  self.running_state_base = None
                  self.running_state = None
          
          
          Severity: Minor
          Found in tests/ssg_test_suite/test_env.py - About 2 hrs to fix

            ContainerTestEnv has 21 functions (exceeds 20 allowed). Consider refactoring.
            Open

            class ContainerTestEnv(TestEnv):
                def __init__(self, scanning_mode, image_name):
                    super(ContainerTestEnv, self).__init__(scanning_mode)
                    self._name_stem = "ssg_test"
                    self.base_image = image_name
            Severity: Minor
            Found in tests/ssg_test_suite/test_env.py - About 2 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):
                  for ref_type, ref_vals in references.items():
                      for ref_val in ref_vals:
                          # This assumes that a single srg key may have items from multiple SRG types
                          if ref_type == 'srg':
              Severity: Minor
              Found in ssg/build_yaml.py - About 2 hrs to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

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

              def get_shell_tasks(tasks):
                  """
                  Find all shell/command module tasks.
                  Module can be as FQCN or just short name.
                  Both forms, free form and 'cmd:' parameter, are supported.
              Severity: Minor
              Found in utils/ansible_shell_diff.py - About 2 hrs to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              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):
                      for dir_item in sorted(os.listdir(guide_directory)):
                          dir_item_path = os.path.join(guide_directory, dir_item)
                          _, extension = os.path.splitext(dir_item)
              
              
              Severity: Minor
              Found in ssg/build_yaml.py - About 2 hrs to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

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

              def walk_products(root, all_products):
                  visited_dirs = set()
              
                  all_rule_dirs = []
                  product_yamls = {}
              Severity: Minor
              Found in utils/rule_dir_json.py - About 2 hrs to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function parse_args has 52 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              def parse_args():
                  parser = argparse.ArgumentParser()
              
                  common_parser = argparse.ArgumentParser(add_help=False)
                  common_parser.set_defaults(test_env=None)
              Severity: Major
              Found in tests/automatus.py - About 2 hrs to fix

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

                def new_stig_overlay(xccdftree, ssgtree, outfile, quiet):
                    if not ssgtree:
                        ssg_mapping = False
                    else:
                        ssg_mapping = ssg_xccdf_stigid_mapping(ssgtree)
                Severity: Minor
                Found in utils/create-stig-overlay.py - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Severity
                Category
                Status
                Source
                Language