def map(self, record_json): if not record_json: return None # Handle a 'Vulnerability' wrapper around the specific record. If not present, assume a direct record if len(list(record_json.keys())) == 1 and record_json.get('Vulnerability'): vuln = record_json['Vulnerability'] else: vuln = record_json db_rec = Vulnerability() db_rec.id = vuln['Name'] db_rec.namespace_name = self.group db_rec.severity = vuln.get('Severity', 'Unknown') db_rec.link = vuln.get('Link') description = vuln.get("Description", "") if description: db_rec.description = vuln.get('Description', '') if len(vuln.get('Description', '')) < self.MAX_STR_LEN else (vuln.get('Description')[:self.MAX_STR_LEN - 8] + '...') else: db_rec.description = "" db_rec.fixed_in = [] # db_rec.vulnerable_in = [] # db_rec.metadata_json = json.dumps(vuln.get('Metadata')) if 'Metadata' in vuln else None db_rec.additional_metadata = vuln.get('Metadata', {}) cvss_data = vuln.get('Metadata', {}).get('NVD', {}).get('CVSSv2') if cvss_data: db_rec.cvss2_vectors = cvss_data.get('Vectors') db_rec.cvss2_score = cvss_data.get('Score') # Process Fixes if 'FixedIn' in vuln: for f in vuln['FixedIn']: fix = FixedArtifact() fix.name = f['Name'] fix.version = f['Version'] fix.version_format = f['VersionFormat'] fix.epochless_version = re.sub(r'^[0-9]*:', '', f['Version']) fix.vulnerability_id = db_rec.id fix.namespace_name = self.group fix.vendor_no_advisory = f.get('VendorAdvisory', {}).get('NoAdvisory', False) fix.fix_metadata = {'VendorAdvisorySummary': f['VendorAdvisory']['AdvisorySummary']} if f.get('VendorAdvisory', {}).get('AdvisorySummary', []) else None db_rec.fixed_in.append(fix) # if 'VulnerableIn' in vuln: # for v in vuln['VulnerableIn']: # v_in = VulnerableArtifact() # v_in.name = v['Name'] # v_in.version = v['Version'] # v_in.version_format = v['VersionFormat'] # v_in.epochless_version = re.sub(r'^[0-9]*:', '', v['Version']) # v_in.vulnerability_id = db_rec.id # v_in.namespace_name = self.group # # db_rec.vulnerable_in.append(v_in) return db_rec
def map(self, record_json): if not record_json: return None # Handle a 'Vulnerability' wrapper around the specific record. If not present, assume a direct record if len(list( record_json.keys())) == 1 and record_json.get("Vulnerability"): vuln = record_json["Vulnerability"] else: vuln = record_json db_rec = Vulnerability() db_rec.id = vuln["Name"] db_rec.namespace_name = self.group db_rec.severity = vuln.get("Severity", "Unknown") db_rec.link = vuln.get("Link") description = vuln.get("Description", "") if description: db_rec.description = ( vuln.get("Description", "") if len(vuln.get("Description", "")) < self.MAX_STR_LEN else (vuln.get("Description")[:self.MAX_STR_LEN - 8] + "...")) else: db_rec.description = "" db_rec.fixed_in = [] # db_rec.vulnerable_in = [] # db_rec.metadata_json = json.dumps(vuln.get('Metadata')) if 'Metadata' in vuln else None db_rec.additional_metadata = vuln.get("Metadata", {}) cvss_data = vuln.get("Metadata", {}).get("NVD", {}).get("CVSSv2") if cvss_data: db_rec.cvss2_vectors = cvss_data.get("Vectors") db_rec.cvss2_score = cvss_data.get("Score") # Process Fixes if "FixedIn" in vuln: for f in vuln["FixedIn"]: fix = FixedArtifact() fix.name = f["Name"] fix.version = f["Version"] fix.version_format = f["VersionFormat"] fix.epochless_version = re.sub(r"^[0-9]*:", "", f["Version"]) fix.vulnerability_id = db_rec.id fix.namespace_name = self.group fix.vendor_no_advisory = f.get("VendorAdvisory", {}).get("NoAdvisory", False) fix.fix_metadata = ({ "VendorAdvisorySummary": f["VendorAdvisory"]["AdvisorySummary"] } if f.get("VendorAdvisory", {}).get("AdvisorySummary", []) else None) db_rec.fixed_in.append(fix) # if 'VulnerableIn' in vuln: # for v in vuln['VulnerableIn']: # v_in = VulnerableArtifact() # v_in.name = v['Name'] # v_in.version = v['Version'] # v_in.version_format = v['VersionFormat'] # v_in.epochless_version = re.sub(r'^[0-9]*:', '', v['Version']) # v_in.vulnerability_id = db_rec.id # v_in.namespace_name = self.group # # db_rec.vulnerable_in.append(v_in) return db_rec