generated from aboutcode-org/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Optionally override package data with new, non-empty manifest data * Expose new experimental API endpoint extra to recollect manifest data with a rescan at collect/reindex_metadata with this override capability * Enable this for Maven only for now Reference: #496 Reference: #494 Signed-off-by: Philippe Ombredanne <[email protected]>
- Loading branch information
1 parent
397e3b3
commit f5b7641
Showing
4 changed files
with
103 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1030,6 +1030,73 @@ def _reindex_package(package, reindexed_packages, **kwargs): | |
serializer = IndexPackagesResponseSerializer(response_data, context={'request': request}) | ||
return Response(serializer.data) | ||
|
||
@extend_schema( | ||
parameters=[ | ||
OpenApiParameter('purl', str, 'query', description='PackageURL', required=True), | ||
], | ||
responses={200:PackageAPISerializer()}, | ||
) | ||
@action(detail=False, methods=['get'], serializer_class=CollectPackageSerializer) | ||
def reindex_metadata(self, request, *args, **kwargs): | ||
""" | ||
Collect or recollect the package metadata of a ``PURL`` string. | ||
Also recollects all packages in the set of the PURL. | ||
If the PURL does exist, calling thios endpoint with re-collect, re-store and return the | ||
Package metadata immediately, | ||
If the package does not exist in the database this call does nothing. | ||
NOTE: this WILL NOT re-run scan and indexing in the background in contrast with the /collect | ||
and collect/index_packages endpoints. | ||
**Request example**:: | ||
/api/collect/reindex_metadata/?purl=pkg:npm/[email protected] | ||
""" | ||
serializer = self.serializer_class(data=request.query_params) | ||
if not serializer.is_valid(): | ||
return Response( | ||
{'errors': serializer.errors}, | ||
status=status.HTTP_400_BAD_REQUEST, | ||
) | ||
|
||
validated_data = serializer.validated_data | ||
purl = validated_data.get('purl') | ||
|
||
lookups = purl_to_lookups(purl) | ||
packages = Package.objects.filter(**lookups) | ||
if packages.count() == 0: | ||
return Response( | ||
{'status': f'Not recollecting: Package does not exist for {purl}'}, | ||
status=status.HTTP_400_BAD_REQUEST, | ||
) | ||
|
||
# Pass to only reindex_metadata downstream | ||
kwargs["reindex_metadata"] = True | ||
# here we have a package(s) matching our purl and we want to recollect metadata live | ||
try: | ||
errors = priority_router.process(purl, **kwargs) | ||
except NoRouteAvailable: | ||
message = { | ||
'status': f'cannot fetch Package data for {purl}: no available handler' | ||
} | ||
return Response(message, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
lookups = purl_to_lookups(purl) | ||
packages = Package.objects.filter(**lookups) | ||
if packages.count() == 0: | ||
message = {} | ||
if errors: | ||
message = { | ||
'status': f'error(s) occurred when fetching metadata for {purl}: {errors}' | ||
} | ||
return Response(message) | ||
|
||
serializer = PackageAPISerializer(packages, many=True, context={'request': request}) | ||
return Response(serializer.data) | ||
|
||
|
||
|
||
class PurlValidateViewSet(viewsets.ViewSet): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters