Skip to content

Instantly share code, notes, and snippets.

@sbs2001
Created August 24, 2020 14:38
Show Gist options
  • Save sbs2001/54087b1ac6be1329dd3fbcac927708e9 to your computer and use it in GitHub Desktop.
Save sbs2001/54087b1ac6be1329dd3fbcac927708e9 to your computer and use it in GitHub Desktop.
scores = {"cvss1":1.2}
data = [
{
"url": "http://lists.opensuse.org/opensuse-security-announce/2019-08/msg00042.html",
"name": "openSUSE-SU-2019:1906",
"refsource": "SUSE",
"tags": [
]
},
{
"url": "http://lists.opensuse.org/opensuse-security-announce/2020-01/msg00040.html",
"name": "openSUSE-SU-2020:0086",
"refsource": "SUSE",
"tags": [
]
},
{
"url": "https://access.redhat.com/errata/RHSA-2019:1587",
"name": "RHSA-2019:1587",
"refsource": "REDHAT",
"tags": [
]
},
{
"url": "https://nvd.nist.gov/vuln/detail/CVE-2019-10160",
"name": "CVE-2019-10160",
"refsource": "NVD",
"tags": [
]
},
]
references = []
for ref in data :
references.append(Reference(url=ref["url"],ref_id=ref["name"], source=ref["refsource"]))
# At importer_runner.py
current_source = "NVD"
obtained_scores_from_nvd_for_CVE_2019_10160 = {"cvss1":1.2}
for ref in references :
ref_obj = ref.save()
if ref.source == current_source :
for scores in obtained_scores_from_nvd_for_CVE_2019_10160.items() :
Score.objects.create(score_type=scores[0], score_value=scores[1], reference=ref_obj)
@pombredanne
Copy link

Yes that's something like this.
Though I would likely avoid

        for scores in obtained_scores_from_nvd_for_CVE_2019_10160.items() : 
            Score.objects.create(score_type=scores[0], score_value=scores[1], reference=ref_obj)

and prefer:

        for score_type, score_value in obtained_scores_from_nvd_for_CVE_2019_10160.items() : 
            Score.objects.create(score_type=score_type, score_value=score_value, reference=ref_obj)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment