ComplianceAsCode/content

View on GitHub

Showing 238 of 1,093 total issues

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

def _find_all_component_contents(self):
"""
Finds and collects all component contents from the XML document.
 
This method iterates over all components in the XML document, extracts relevant
Severity: Minor
Found in ssg/xml.py - About 35 mins to fix

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

def choose_variable_value(self, var_id, variables, refinements):
"""
Determine value of variable based on profile refinements.
"""
if refinements and var_id in refinements:
Severity: Minor
Found in ssg/playbook_builder.py - About 35 mins to fix

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

def _open_yaml(stream, original_file=None, substitutions_dict={}):
"""
Open given file-like object and parse it as YAML.
 
Args:
Severity: Minor
Found in ssg/yaml.py - About 35 mins to fix

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

def get_variable_values(content_dir: str, profiles_variables: dict) -> dict_type:
"""
Update the variables dictionary with actual values for each variable option.
 
Given a content root directory and a dictionary of variables, this function retrieves the
Severity: Minor
Found in ssg/variables.py - About 35 mins to fix

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

def _subtract_refinements(self):
"""
From the resolved profile, "undo" every refinement prefixed with '!' in this profile.
"""
for rule, refinements in list(self.refine_rules.items()):
Severity: Minor
Found in ssg/entities/common.py - About 35 mins to fix

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

def fill_queue(benchmarks, benchmark_profile_pairs, input_path, path_base,
output_dir):
"""
For each benchmark and profile in the benchmark, create a queue of
tasks for later processing. A task is a named tuple (benchmark_id,
Severity: Minor
Found in ssg/build_guides.py - About 35 mins to fix

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

def __init__(self, filepath, product=""):
self.tree = None
try:
with open(filepath, 'r') as xccdf_file:
file_string = xccdf_file.read()
Severity: Minor
Found in ssg/build_profile.py - About 35 mins to fix

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

def process_input_dict(cls, input_contents, env_yaml, product_cpes):
input_contents = super(Profile, cls).process_input_dict(input_contents, env_yaml)
 
platform = input_contents.get("platform")
if platform is not None:
Severity: Minor
Found in ssg/entities/profile_base.py - About 35 mins to fix

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

def parse_affected(oval_contents):
"""
Returns the tuple (start_affected, end_affected, platform_indents) for the passed OVAL file contents.
 
Args:
Severity: Minor
Found in ssg/oval.py - About 35 mins to fix

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

def _has_invalid_param(root: str, test_file: str) -> bool:
full_path = os.path.join(root, test_file)
has_no_errors = True
with open(full_path, "r") as f:
for line in f:
Severity: Minor
Found in tests/validate_automatus_metadata.py - About 35 mins to fix

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

def check_all_rules(root, filter_profiles):
rules_missing_cce = []
root = ssg.xml.parse_file(args.datastream_path)
for benchmark in root.findall(".//{%s}Benchmark" % (XCCDF12_NS)):
selected_rules = get_selected_rules(benchmark, filter_profiles)
Severity: Minor
Found in tests/missing_cces.py - About 35 mins to fix

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

def fetch_all_templated_tests_paths(rule_template):
"""
Builds a dictionary of a test case relative path -> test case absolute path mapping.
 
Here, we want to know what the relative path on disk (under the tests/
Severity: Minor
Found in tests/ssg_test_suite/common.py - About 35 mins to fix

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

def _remove_files_to_clean(self):
if self.clean_files:
for fname in tuple(self._filenames_to_clean_afterwards):
try:
if os.path.exists(fname):
Severity: Minor
Found in tests/ssg_test_suite/oscap.py - About 35 mins to fix

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

def flatten_stig_results(stig_results: dict) -> dict:
base_stig_flat_results = dict()
for stig, results in stig_results.items():
if len(results) == 1:
base_stig_flat_results[stig] = results[0]
Severity: Minor
Found in utils/compare_results.py - About 35 mins to fix

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

def preprocess(data, lang):
data["check_root_user"] = parse_template_boolean_value(data, parameter="check_root_user", default_value=False)
if "key" not in data:
data["key"] = "perm_mod"
if lang == "bash":
Severity: Minor
Found in shared/templates/audit_rules_dac_modification/template.py - About 35 mins to fix

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

def preprocess(data, lang):
if lang == "oval":
pathid = ssg.utils.escape_id(data["path"])
# remove root slash made into '_'
pathid = pathid[1:]
Severity: Minor
Found in shared/templates/audit_rules_path_syscall/template.py - About 35 mins to fix

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

def group_symbolic_permissions(mode_dict):
search_mode = ''
fix_mode = ''
for k in mode_dict:
if mode_dict[k] != '':
Severity: Minor
Found in shared/templates/file_permissions/template.py - About 35 mins to fix

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

def get_requirements_with_no_cces(sheet: Worksheet, end_row: int) -> list:
result = list()
for i in range(2, end_row):
requirement = sheet[f'F{i}'].value
if requirement is None or requirement.strip() == "":
Severity: Minor
Found in utils/srg_diff.py - About 35 mins to fix

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

def main():
ssg_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
max_path = ""
for dir_, _, files in os.walk(ssg_root):
# Don't check for path len of log files
Severity: Minor
Found in tests/ensure_paths_are_short.py - About 35 mins to fix

Avoid too many return statements within this function.
Open

return self._generate_meta_content()
Severity: Major
Found in utils/ansible_playbook_to_role.py - About 30 mins to fix
    Severity
    Category
    Status
    Source
    Language