From 6ed1697a84902974910942e0e90bd4049ab58bb9 Mon Sep 17 00:00:00 2001 From: Matthew Burket Date: Wed, 18 Oct 2023 11:46:24 -0500 Subject: [PATCH] Fix Codeclimate issues --- utils/refchecker.py | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/utils/refchecker.py b/utils/refchecker.py index 3edc55f68d0..08d9b0b4d61 100755 --- a/utils/refchecker.py +++ b/utils/refchecker.py @@ -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}" @@ -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: @@ -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()