Skip to content

Commit

Permalink
Fix Codeclimate issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Mab879 committed Oct 18, 2023
1 parent c492fb0 commit 6ed1697
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions utils/refchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,37 @@ def load_for_product(rule_obj, product, env_yaml=None):
return rule


def reference_check(env_yaml, rule_dirs, profile_path, product, product_yaml, reference,
excludes, controls_manager=None):
profile = ssg.build_yaml.ProfileWithInlinePolicies.from_yaml(profile_path, env_yaml)
def _process_controls_manager(controls_manager, env_yaml, product_yaml, profile, rule_dirs):
product_cpes = ProductCPEs()
product_cpes.load_product_cpes(env_yaml)
product_cpes.load_content_cpes(env_yaml)

exc = _process_excludes(excludes)

if controls_manager:
profile_files = ssg.products.get_profile_files_from_root(env_yaml, product_yaml)
all_profiles = ssg.build_profile.make_name_to_profile_mapping(profile_files, env_yaml,
product_cpes)
profile.resolve(all_profiles, rule_dirs, controls_manager)


def _process_excludes(excludes):
if not excludes or excludes == '':
return list()
result = list()
if ',' not in excludes:
result.append(excludes)
return result
for item in excludes.split(','):
result.append(item.strip())
return result


def reference_check(env_yaml, rule_dirs, profile_path, product, product_yaml, reference,
excludes, controls_manager=None):
profile = ssg.build_yaml.ProfileWithInlinePolicies.from_yaml(profile_path, env_yaml)
_process_controls_manager(controls_manager, env_yaml, product_yaml, profile, rule_dirs)

ok = True
processed_excludes = _process_excludes(excludes)

for rule_id in profile.selected + profile.unselected:
if rule_id not in rule_dirs:
msg = "Unable to find rule in rule_dirs.json: {0}"
Expand All @@ -91,7 +106,7 @@ def reference_check(env_yaml, rule_dirs, profile_path, product, product_yaml, re

rule = load_for_product(rule_dirs[rule_id], product, env_yaml=env_yaml)

if rule_id in exc:
if rule_id in processed_excludes:
continue

if reference not in rule.references:
Expand All @@ -103,18 +118,6 @@ def reference_check(env_yaml, rule_dirs, profile_path, product, product_yaml, re
return ok


def _process_excludes(excludes):
if not excludes or excludes == '':
return list()
result = list()
if ',' not in excludes:
result.append(excludes)
return result
for item in excludes.split(','):
result.append(item.strip())
return result


def main():
args = parse_args()

Expand Down

0 comments on commit 6ed1697

Please sign in to comment.