ComplianceAsCode/content

View on GitHub

Showing 1,039 of 1,039 total issues

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

        try:
            podman_output = subprocess.check_output(podman_cmd, stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            msg = "Command '{0}' returned {1}:\n{2}".format(
                " ".join(e.cmd), e.returncode, e.output.decode("utf-8"))
Severity: Major
Found in tests/ssg_test_suite/test_env.py and 2 other locations - About 3 hrs to fix
tests/ssg_test_suite/test_env.py on lines 540..545
tests/ssg_test_suite/test_env.py on lines 554..559

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 66.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

        try:
            podman_output = subprocess.check_output(podman_cmd, stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            msg = "Command '{0}' returned {1}:\n{2}".format(
                " ".join(e.cmd), e.returncode, e.output.decode("utf-8"))
Severity: Major
Found in tests/ssg_test_suite/test_env.py and 2 other locations - About 3 hrs to fix
tests/ssg_test_suite/test_env.py on lines 554..559
tests/ssg_test_suite/test_env.py on lines 568..573

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 66.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

        try:
            podman_output = subprocess.check_output(podman_cmd, stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            msg = "Command '{0}' returned {1}:\n{2}".format(
                " ".join(e.cmd), e.returncode, e.output.decode("utf-8"))
Severity: Major
Found in tests/ssg_test_suite/test_env.py and 2 other locations - About 3 hrs to fix
tests/ssg_test_suite/test_env.py on lines 540..545
tests/ssg_test_suite/test_env.py on lines 568..573

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 66.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

File rule_dir_stats.py has 453 lines of code (exceeds 400 allowed). Consider refactoring.
Open

"""
This module contains common code shared by utils/rule_dir_stats.py and utils/rule_dir_diff.py.
This code includes functions for walking the output of the utils/rule_dir_json.py script, and
filtering functions used in both scripts.
"""
Severity: Minor
Found in ssg/rule_dir_stats.py - About 3 hrs to fix

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

        for _, elem in candidates:
            _id = elem.get("id")
            if _id is None:
                continue
    
    
    Severity: Major
    Found in ssg/xccdf.py and 1 other location - About 3 hrs to fix
    ssg/xccdf.py on lines 80..90

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 65.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

                for elem in benchmark.findall(".//{%s}Profile" % (namespace)):
                    id_ = elem.get("id")
                    if id_ is None:
                        continue
    
    
    Severity: Major
    Found in ssg/xccdf.py and 1 other location - About 3 hrs to fix
    ssg/xccdf.py on lines 37..47

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 65.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

                if options.disarefs_not_in_profile:
                    if (disa_ref_href in ref_href_list) and (rule.get("id") not in profile_ruleids):
                        print("ERROR: XCCDF Rule found with DISA CCI reference outside Profile %s: "
                               % options.profile_name + rule.get("id"))
                        exit_value = 1
    Severity: Major
    Found in build-scripts/verify_references.py and 1 other location - About 3 hrs to fix
    build-scripts/verify_references.py on lines 277..281

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 65.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

                if options.nistrefs_not_in_profile:
                    if (nist_ref_href in ref_href_list) and (rule.get("id") not in profile_ruleids):
                        print("ERROR: XCCDF Rule found with NIST reference outside Profile %s: "
                               % options.profile_name + rule.get("id"))
                        exit_value = 1
    Severity: Major
    Found in build-scripts/verify_references.py and 1 other location - About 3 hrs to fix
    build-scripts/verify_references.py on lines 283..287

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 65.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    class Benchmark(XCCDFEntity):
        """Represents XCCDF Benchmark
        """
        KEYS = dict(
            status=lambda: "",
    Severity: Minor
    Found in ssg/build_yaml.py - About 3 hrs to fix

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

      class RuleChecker(oscap.Checker):
          """
          Rule checks generally work like this -
          for every profile that supports that rule:
      
      
      Severity: Minor
      Found in tests/ssg_test_suite/rule.py - About 3 hrs to fix

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

                    try:
                        subprocess.check_output(podman_cmd, stderr=subprocess.STDOUT)
                    except subprocess.CalledProcessError as e:
                        msg = "Command '{0}' returned {1}:\n{2}".format(
                            " ".join(e.cmd), e.returncode, e.output.decode("utf-8"))
        Severity: Major
        Found in tests/ssg_test_suite/test_env.py and 3 other locations - About 3 hrs to fix
        tests/ssg_test_suite/test_env.py on lines 521..526
        tests/ssg_test_suite/test_env.py on lines 598..603
        tests/ssg_test_suite/test_env.py on lines 607..612

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 64.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

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

                try:
                    subprocess.check_output(podman_cmd, stderr=subprocess.STDOUT)
                except subprocess.CalledProcessError as e:
                    msg = "Command '{0}' returned {1}:\n{2}".format(
                        " ".join(e.cmd), e.returncode, e.output.decode("utf-8"))
        Severity: Major
        Found in tests/ssg_test_suite/test_env.py and 3 other locations - About 3 hrs to fix
        tests/ssg_test_suite/test_env.py on lines 521..526
        tests/ssg_test_suite/test_env.py on lines 591..596
        tests/ssg_test_suite/test_env.py on lines 598..603

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 64.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

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

                    try:
                        subprocess.check_output(podman_cmd, stderr=subprocess.STDOUT)
                    except subprocess.CalledProcessError as e:
                        msg = "Command '{0}' returned {1}:\n{2}".format(
                            " ".join(e.cmd), e.returncode, e.output.decode("utf-8"))
        Severity: Major
        Found in tests/ssg_test_suite/test_env.py and 3 other locations - About 3 hrs to fix
        tests/ssg_test_suite/test_env.py on lines 521..526
        tests/ssg_test_suite/test_env.py on lines 591..596
        tests/ssg_test_suite/test_env.py on lines 607..612

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 64.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

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

                try:
                    subprocess.check_output(podman_cmd, stderr=subprocess.STDOUT)
                except subprocess.CalledProcessError as e:
                    msg = "Command '{0}' returned {1}:\n{2}".format(
                        " ".join(e.cmd), e.returncode, e.output.decode("utf-8"))
        Severity: Major
        Found in tests/ssg_test_suite/test_env.py and 3 other locations - About 3 hrs to fix
        tests/ssg_test_suite/test_env.py on lines 591..596
        tests/ssg_test_suite/test_env.py on lines 598..603
        tests/ssg_test_suite/test_env.py on lines 607..612

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 64.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

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

            def _final_scan_went_ok(self, runner, rule_id):
                success = runner.run_stage_with_context('final', 'pass')
                self._current_result.record_stage_result("final_scan", success)
                if not success:
                    msg = ("The check after remediation failed for rule '{}'."
        Severity: Major
        Found in tests/ssg_test_suite/rule.py and 1 other location - About 3 hrs to fix
        tests/ssg_test_suite/rule.py on lines 203..211

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 63.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

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

            def _remediation_went_ok(self, runner, rule_id):
                success = runner.run_stage_with_context('remediation', 'fixed')
                self._current_result.record_stage_result("remediation", success)
                if not success:
                    msg = ("The remediation failed for rule '{}'."
        Severity: Major
        Found in tests/ssg_test_suite/rule.py and 1 other location - About 3 hrs to fix
        tests/ssg_test_suite/rule.py on lines 213..220

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 63.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        File constants.py has 442 lines of code (exceeds 400 allowed). Consider refactoring.
        Open

        from __future__ import absolute_import
        from __future__ import print_function
        
        import os.path
        import os
        Severity: Minor
        Found in ssg/constants.py - About 3 hrs to fix

          Cyclomatic complexity is too high in method _start_operation. (18)
          Open

              def _start_operation(self, ast, operation, precedence):
                  """
                  Return an AST where all operations of lower precedence are finalized.
                  """
                  if TRACE_PARSE:
          Severity: Minor
          Found in ssg/ext/boolean/boolean.py by radon

          Cyclomatic Complexity

          Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

          Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

          Construct Effect on CC Reasoning
          if +1 An if statement is a single decision.
          elif +1 The elif statement adds another decision.
          else +0 The else statement does not cause a new decision. The decision is at the if.
          for +1 There is a decision at the start of the loop.
          while +1 There is a decision at the while statement.
          except +1 Each except branch adds a new conditional path of execution.
          finally +0 The finally block is unconditionally executed.
          with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
          assert +1 The assert statement internally roughly equals a conditional statement.
          Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
          Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

          Source: http://radon.readthedocs.org/en/latest/intro.html

          Function move_patches_up_to_date_to_source_data_stream_component has a Cognitive Complexity of 23 (exceeds 7 allowed). Consider refactoring.
          Open

          def move_patches_up_to_date_to_source_data_stream_component(datastreamtree):
              ds_checklists = datastreamtree.find(
                  ".//{%s}checklists" % datastream_namespace)
              checklists_component_ref = ds_checklists.find(
                  "{%s}component-ref" % datastream_namespace)
          Severity: Minor
          Found in build-scripts/compose_ds.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_rules_parallel has a Cognitive Complexity of 23 (exceeds 7 allowed). Consider refactoring.
          Open

          def walk_rules_parallel(args, left_rules, right_rules, oval_func, remediation_func):
              """
              Walks two sets of known_rules (left_rules and right_rules) with identical keys and returns
              left_only, right_only, and common_only output from _walk_rule.
          
          
          Severity: Minor
          Found in ssg/rule_dir_stats.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

          Severity
          Category
          Status
          Source
          Language