def get_consolidated_checklist()

in scripts/create_master_checklist.py [0:0]


def get_consolidated_checklist(input_folder, language, service_dictionary=None):
    # Initialize checklist object
    checklist_master_data = {
        'items': [],
        'metadata': {
            'name': 'Master checklist',
            'timestamp': datetime.date.today().strftime("%B %d, %Y")
        }
    }
    if args.waf:
        checklist_master_data['metadata']['name'] = 'WAF checklist'
    # Find all files in the input folder matching the pattern "language*.json"
    if args.verbose:
        print("DEBUG: looking for JSON files in folder", input_folder, "with pattern *.", language + ".json...")
    checklist_files = glob.glob(input_folder + "/*." + language + ".json")
    if args.verbose:
        print("DEBUG: found", len(checklist_files), "JSON files")
    for checklist_file in checklist_files:
        if checklist_is_valid(checklist_file, language):
            # Get JSON
            try:
                with open(checklist_file) as f:
                    checklist_data = json.load(f)
                    if args.verbose:
                        print("DEBUG: JSON file", checklist_file, "loaded successfully with {0} items".format(len(checklist_data["items"])))
                    # Verify that the checklist is not deprecated
                    if "metadata" in checklist_data and "state" in checklist_data["metadata"] and "deprecated" in checklist_data["metadata"]["state"].lower():
                        if args.verbose:
                            print("DEBUG: skipping deprecated checklist", checklist_file)
                    else:
                        # Additional check if we are only interested in WAF recommendations:
                        #   If the WAF argument was provided, only checklists with WAF attribute containing a valid value will be processed
                        if not args.waf or contains_waf(checklist_data["metadata"]):
                            # Go over each checklist item
                            for item in checklist_data["items"]:
                                # Add field with the name of the checklist
                                item["checklist"] = checklist_data["metadata"]["name"]
                                # Cleanup some fields
                                item.pop("id", None)
                                item.pop("cost", None)
                                item.pop("simple", None)
                                item.pop("ha", None)
                                item.pop("scale", None)
                                item.pop("security", None)
                                if args.waf:
                                    item.pop("category", None)
                                    item.pop("subcategory", None)
                                # Additional check if we are only interested in WAF recommendations: only items with WAF pillar and service will be added
                                if not args.waf or ("waf" in item and "service" in item):
                                    # Add items to the master checklist
                                    checklist_master_data['items'] += [item]
                            # Replace the master checklist severities and status sections (for a given language they should be all the same)
                            checklist_master_data['severities'] = checklist_data['severities']
                            checklist_master_data['status'] = checklist_data['status']
            except Exception as e:
                print("ERROR: Error when processing JSON file", checklist_file, "-", str(e))
            # Optionally, browse the checklist items and add the services field
            if args.add_services and not args.waf:
                for item in checklist_master_data["items"]:
                    # Get service from the checklist name
                    services = []
                    if "checklist" in item:
                        services += get_services_from_string(item["checklist"])
                    if "text" in item:
                        services += get_services_from_string(item["text"])
                    if "category" in item:
                        services += get_services_from_string(item["category"])
                    if "subcategory" in item:
                        services += get_services_from_string(item["subcategory"])
                    if "description" in item:
                        services += get_services_from_string(item["description"])
                    item["services"] = list(set(services))
            # Optionally, browse the checklist items and add the ARM service field
            if args.add_arm_services and args.waf and service_dictionary:
                for item in checklist_master_data["items"]:
                    arm_service = get_arm_service_name(item["service"], service_dictionary=service_dictionary)
                    if arm_service:
                        item["arm-service"] = arm_service
    if args.verbose:
        print("DEBUG: master checklist contains", len(checklist_master_data["items"]), "items")
    return checklist_master_data