def create(item: RestrictedElement) -> models.Cwe: cwe_id = 'CWE-{}'.format(item.get('ID')) try: cwe = models.Cwe.objects.get(id=cwe_id) except models.Cwe.DoesNotExist: cwe = models.Cwe(id=cwe_id) for field in sorted(CWEFactory.FIELD_LIST): parser = getattr(CWEFactory, field, None) if parser: setattr(cwe, field, parser(item)) if cwe.has_changed: cwe.save() return cwe
def create(item: RestrictedElement): cwe_id = 'CWE-{}'.format(item.get('ID')) old = CweDocument.search().filter( 'term', id=cwe_id).sort('-modified_date')[0].execute() cwe = CweDocument(id=cwe_id) for field in CweDocument.get_fields_name(): parser = getattr(CWEFactory, field, None) if parser: setattr(cwe, field, parser(item)) if old.hits and cwe.has_changed(old.hits[0]): return old.hits[0].update(cwe, weak=True) elif not old.hits: return cwe.save(weak=True) return None
def status(item: RestrictedElement) -> str: return item.get('Status')
def weakness_abstraction(item: RestrictedElement) -> str: return item.get('Weakness_Abstraction')
def name(item: RestrictedElement) -> str: return item.get('Name')
def vendor(item: RestrictedElement) -> str: return CpeFactory.get_field(item.get('name'), CpeFactory.VENDOR)