<commit_before>import json

from dojo.models import Finding


class HadolintParser(object):

    def get_scan_types(self):
        return ["Hadolint Dockerfile check"]

    def get_label_for_scan_types(self, scan_type):
        return scan_type  # no custom label for now

    def get_description_for_scan_types(self, scan_type):
        return "Import Hadolint Dockerfile check findings in JSON format."

    def get_findings(self, json_output, test):
        tree = json.load(json_output)
        return self.get_items(tree, test)

    def get_items(self, tree, test):
        items = {}
        for node in tree:
            item = get_item(node, test)
            unique_key = str(node['line']) + "-" + str(node['column']) + node['code'] + node['file']
            items[unique_key] = item

        return items.values()


def get_item(vulnerability, test):
    if 'level' in vulnerability:
        # If we're dealing with a license finding, there will be no cvssScore
        if vulnerability['level'] == "error":
            severity = "Critical"
        elif vulnerability['level'] == "warning":
            severity = "High"
        else:
            severity = "Info"
    # TODO: some seem to not have anything. Needs UNKNOWN new status in the model. Some vuln do not yet have cvss assigned.
    else:
        severity = "Info"

    # create the finding object
    finding = Finding(
        title=vulnerability['code'] + ": " + vulnerability['file'],
        test=test,
        severity=severity,
        description="File: {}:{}\nVulnerability ID: {}\nDetails: {}\n".format(vulnerability['file'], vulnerability['line'], vulnerability['code'], vulnerability['message']),
        mitigation="No mitigation provided",
        false_p=False,
        duplicate=False,
        out_of_scope=False,
        mitigated=None,
        impact="No impact provided")

    finding.description = finding.description.strip()

    return finding<commit_msg>Mark Hadolint findings as static (#4746)<commit_after>import json

from dojo.models import Finding


class HadolintParser(object):

    def get_scan_types(self):
        return ["Hadolint Dockerfile check"]

    def get_label_for_scan_types(self, scan_type):
        return scan_type  # no custom label for now

    def get_description_for_scan_types(self, scan_type):
        return "Import Hadolint Dockerfile check findings in JSON format."

    def get_findings(self, json_output, test):
        tree = json.load(json_output)
        return self.get_items(tree, test)

    def get_items(self, tree, test):
        items = {}
        for node in tree:
            item = get_item(node, test)
            unique_key = str(node['line']) + "-" + str(node['column']) + node['code'] + node['file']
            items[unique_key] = item

        return items.values()


def get_item(vulnerability, test):
    if 'level' in vulnerability:
        # If we're dealing with a license finding, there will be no cvssScore
        if vulnerability['level'] == "error":
            severity = "Critical"
        elif vulnerability['level'] == "warning":
            severity = "High"
        else:
            severity = "Info"
    # TODO: some seem to not have anything. Needs UNKNOWN new status in the model. Some vuln do not yet have cvss assigned.
    else:
        severity = "Info"

    # create the finding object, with 'static' type
    finding = Finding(
        title=vulnerability['code'] + ": " + vulnerability['file'],
        test=test,
        severity=severity,
        description="File: {}:{}\nVulnerability ID: {}\nDetails: {}\n".format(vulnerability['file'], vulnerability['line'], vulnerability['code'], vulnerability['message']),
        mitigation="No mitigation provided",
        false_p=False,
        duplicate=False,
        static_finding=True,
        dynamic_finding=False,
        out_of_scope=False,
        mitigated=None,
        impact="No impact provided")

    finding.description = finding.description.strip()

    return finding
{'fraction_non_alphanumeric': 0.11136079900124844, 'fraction_numerical': 0.0009987515605493133, 'mean_word_length': 2.782813975448536, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6117540', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1111, 'n_words': 319}