Skip to content

Commit

Permalink
code-cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: NucleonGodX <[email protected]>
  • Loading branch information
NucleonGodX committed Jan 23, 2025
1 parent ba07d6d commit 9374f7e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions vulnerabilities/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,17 @@ class Meta:
"subpath",
"purl",
]
order_by = ["type", "namespace", "name", "-version", "qualifiers", "subpath"]

def filter_purl(self, queryset, name, value):
purl = unquote(value)
try:
purl = PackageURL.from_string(purl)

except ValueError as ve:
raise serializers.ValidationError(
detail={"error": f'"{purl}" is not a valid Package URL: {ve}'},
)

lookups = get_purl_query_lookups(purl)
return self.queryset.filter(**lookups)

Expand Down Expand Up @@ -466,9 +467,7 @@ class PackageViewSet(viewsets.ReadOnlyModelViewSet):
Lookup for vulnerable packages by Package URL.
"""

queryset = Package.objects.all().order_by(
"type", "namespace", "name", "-version", "qualifiers", "subpath"
)
queryset = Package.objects.all()
serializer_class = PackageSerializer
filter_backends = (filters.DjangoFilterBackend,)
filterset_class = PackageFilterSet
Expand Down Expand Up @@ -747,4 +746,4 @@ class AliasViewSet(VulnerabilityViewSet):
(https://nvd.nist.gov/general/cve-process).
"""

filterset_class = AliasFilterSet
filterset_class = AliasFilterSet

0 comments on commit 9374f7e

Please sign in to comment.