예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
 def status(item: RestrictedElement) -> str:
     return item.get('Status')
예제 #4
0
 def weakness_abstraction(item: RestrictedElement) -> str:
     return item.get('Weakness_Abstraction')
예제 #5
0
 def name(item: RestrictedElement) -> str:
     return item.get('Name')
예제 #6
0
 def vendor(item: RestrictedElement) -> str:
     return CpeFactory.get_field(item.get('name'), CpeFactory.VENDOR)