def add_or_update_cve(data): for cve_id, advisory in data['advisories'].iteritems(): if not advisory.get('feed', True): # skip advisories with `feed: false` continue cve_year, cve_order = parse_cve_id(cve_id) update_advisory_bugs(advisory) cve_title = advisory.get('cve_problemtype', advisory.get('title')) or '' cve_data = { 'id': cve_id, 'year': cve_year, 'order': cve_order, 'title': cve_title, 'impact': advisory['impact'] or '', 'reporter': advisory['reporter'] or '', 'description': advisory['description'] or '', 'bugs': advisory['bugs'], } try: cve = MitreCVE.objects.get(id=cve_id) except MitreCVE.DoesNotExist: cve = MitreCVE(**cve_data) cve.products = data['fixed_in'] cve.mfsa_ids.append(data['mfsa_id']) else: cve.products = list(set(cve.products).union(data['fixed_in'])) cve.mfsa_ids = list(set(cve.mfsa_ids).union([data['mfsa_id']])) for prop, value in cve_data.items(): if value: setattr(cve, prop, value) cve.save()
def add_or_update_cve(data): for cve_id, advisory in data["advisories"].items(): if not cve_id.startswith("CVE-"): # skip advisories that are not CVE continue if not advisory.get("feed", True): # skip advisories with `feed: false` continue cve_year, cve_order = parse_cve_id(cve_id) update_advisory_bugs(advisory) cve_title = advisory.get("cve_problemtype", advisory.get("title")) or "" cve_data = { "id": cve_id, "year": cve_year, "order": cve_order, "title": cve_title, "impact": advisory["impact"] or "", "reporter": advisory["reporter"] or "", "description": advisory["description"] or "", "bugs": advisory["bugs"], } try: cve = MitreCVE.objects.get(id=cve_id) except MitreCVE.DoesNotExist: cve = MitreCVE(**cve_data) cve.products = data["fixed_in"] cve.mfsa_ids.append(data["mfsa_id"]) else: cve.products = list(set(cve.products).union(data["fixed_in"])) cve.mfsa_ids = list(set(cve.mfsa_ids).union([data["mfsa_id"]])) for prop, value in cve_data.items(): if value: setattr(cve, prop, value) cve.save()