Skip to content

Commit c4e617d

Browse files
committed
Improve model doc and apply minor refactoring
In PackageQuerySet - Align processing in for_purls and for_purl manager methods - Correctly reference Package and not Vulnerability Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent f245491 commit c4e617d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

vulnerabilities/models.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import hashlib
1111
import json
1212
import logging
13+
import typing
1314
from contextlib import suppress
1415
from functools import cached_property
1516
from typing import Optional
@@ -522,7 +523,13 @@ def for_purl(self, purl):
522523
"""
523524
Return a queryset matching the ``purl`` Package URL.
524525
"""
525-
return self.filter(**purl_to_dict(purl))
526+
return self.filter(package_url=purl)
527+
528+
def for_purls(self, purls=()):
529+
"""
530+
Return a queryset of Packages matching a list of PURLs.
531+
"""
532+
return self.filter(package_url__in=purls).distinct()
526533

527534
def with_cpes(self):
528535
"""
@@ -532,24 +539,21 @@ def with_cpes(self):
532539

533540
def for_cpe(self, cpe):
534541
"""
535-
Return a queryset of Vulnerability that have the ``cpe`` as an NVD CPE reference.
542+
Return a queryset of Packages that have the ``cpe`` as an NVD CPE reference.
536543
"""
537544
return self.filter(vulnerabilities__vulnerabilityreference__reference_id__exact=cpe)
538545

539546
def with_cves(self):
540547
"""
541-
Return a queryset of Vulnerability that have one or more NVD CVE aliases.
548+
Return a queryset of Packages that have one or more NVD CVE aliases.
542549
"""
543550
return self.filter(vulnerabilities__aliases__alias__startswith="CVE")
544551

545552
def for_cve(self, cve):
546553
"""
547-
Return a queryset of Vulnerability that have the the NVD CVE ``cve`` as an alias.
554+
Return a queryset of Packages that have the NVD CVE ``cve`` as a vulnerability alias.
548555
"""
549-
return self.filter(vulnerabilities__vulnerabilityreference__reference_id__exact=cve)
550-
551-
def for_purls(self, purls=[]):
552-
return Package.objects.filter(package_url__in=purls).distinct()
556+
return self.filter(vulnerabilities__aliases__alias=cve)
553557

554558
def with_is_vulnerable(self):
555559
"""

0 commit comments

Comments
 (0)