def main(): args = parse_args() env_yaml = ssg.yaml.open_environment( args.build_config_yaml, args.product_yaml) product = ssg.utils.required_key(env_yaml, "product") product_dir = os.path.dirname(args.product_yaml) relative_guide_dir = ssg.utils.required_key(env_yaml, "benchmark_root") guide_dir = os.path.abspath(os.path.join(product_dir, relative_guide_dir)) # As fixes is continually updated, the last seen fix that is applicable for a # given fix_name is chosen to replace newer fix_names remediation_cls = remediation.REMEDIATION_TO_CLASS[args.remediation_type] rule_id_to_remediation_map = collect_fixes( product, guide_dir, args.fix_dirs, args.remediation_type) fixes = dict() for rule_id, fix_path in rule_id_to_remediation_map.items(): remediation_obj = remediation_cls(fix_path) rule_path = os.path.join(args.resolved_rules_dir, rule_id + ".yml") if os.path.isfile(rule_path): remediation_obj.load_rule_from(rule_path) # Fixes gets updated with the contents of the fix # if it is applicable remediation.process(remediation_obj, env_yaml, fixes, rule_id) remediation.write_fixes_to_dir(fixes, args.remediation_type, args.output_dir) sys.stderr.write("Collected %d %s remediations.\n" % (len(fixes), args.remediation_type)) sys.exit(0)
def main(): args = parse_args() env_yaml = ssg.yaml.open_environment(args.build_config_yaml, args.product_yaml) product = ssg.utils.required_key(env_yaml, "product") product_dir = os.path.dirname(args.product_yaml) relative_guide_dir = ssg.utils.required_key(env_yaml, "benchmark_root") guide_dir = os.path.abspath(os.path.join(product_dir, relative_guide_dir)) # As fixes is continually updated, the last seen fix that is applicable for a # given fix_name is chosen to replace newer fix_names remediation_cls = remediation.REMEDIATION_TO_CLASS[args.remediation_type] fixes = dict() for fixdir in args.fix_dirs: if os.path.isdir(fixdir): for filename in os.listdir(fixdir): file_path = os.path.join(fixdir, filename) fix_name, _ = os.path.splitext(filename) remediation_obj = remediation_cls(env_yaml, args.resolved_rules_dir, product, file_path, fix_name) # Fixes gets updated with the contents of the fix, if it is applicable remediation_obj.process(fixes) # Walk the guide last, looking for rule folders as they have the highest priority for _dir_path in ssg.rules.find_rule_dirs(guide_dir): rule_id = ssg.rules.get_rule_dir_id(_dir_path) contents = ssg.rules.get_rule_dir_remediations(_dir_path, args.remediation_type, product) for _path in reversed(contents): # To be compatible with the later checks, use the rule_id # (i.e., the value of _dir) to create the fix_name remediation_obj = remediation_cls(env_yaml, args.resolved_rules_dir, product, _path, rule_id) # Fixes gets updated with the contents of the fix, if it is applicable remediation_obj.process(fixes) remediation.write_fixes_to_dir(fixes, args.remediation_type, args.output_dir) sys.stderr.write("Collected %d %s remediations.\n" % (len(fixes), args.remediation_type)) sys.exit(0)