generated from aboutcode-org/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add golang purl service #316
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7db96ce
Add to_purl endpoint for getting golang purl from go_import
TG1999 1c5d534
Add tests
TG1999 4cc48ce
Update dependencies
TG1999 7c24793
Fix tests
TG1999 9a8a935
Correct view name
TG1999 c9cbf54
Correct description
TG1999 4d13060
Fix tests
TG1999 6affbcc
Fix tests
TG1999 b29dc59
Address review comments
TG1999 a97b197
Address review comments
TG1999 bea27d1
Fix tests
TG1999 17fc81a
Add docs
TG1999 be5dc3e
Fix tests
TG1999 902b09b
Incorporate suggested chnages
TG1999 87ba3c1
Update docstring
TG1999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1179,3 +1179,11 @@ def test_api_purl_validation_empty_request(self): | |
} | ||
|
||
self.assertAlmostEquals(expected, response1.data) | ||
|
||
|
||
class ToGolangPurlTestCase(TestCase): | ||
|
||
def test_to_golang_purl(self): | ||
response = self.client.get("/api/to_purl/go", data={"go_package": "github.com/gorilla/[email protected]"}, follow=True) | ||
expected = "pkg:golang/github.com/gorilla/mux%40v1.7.3" | ||
self.assertEqual(expected, response.data["golang_purl"]) |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# | ||
# Copyright (c) nexB Inc. and others. All rights reserved. | ||
# purldb is a trademark of nexB Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text. | ||
# See https://github.com/nexB/purldb for support or download. | ||
# See https://aboutcode.org for more information about nexB OSS projects. | ||
# | ||
|
||
from django.db import router | ||
from drf_spectacular.utils import OpenApiParameter, extend_schema | ||
from packageurl.utils import get_golang_purl | ||
from rest_framework import status | ||
from rest_framework import viewsets | ||
from rest_framework.response import Response | ||
|
||
from packagedb.serializers import GoLangPurlResponseSerializer | ||
from packagedb.serializers import GoLangPurlSerializer | ||
from rest_framework import routers | ||
|
||
|
||
@extend_schema( | ||
parameters=[ | ||
OpenApiParameter("go_package", str, "query", description="go import package"), | ||
], | ||
responses={200: GoLangPurlResponseSerializer()}, | ||
) | ||
class GolangPurlViewSet(viewsets.ViewSet): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need some docsting. Being more explicit about the fact that the endpoint accepts a standard Go import string and returns the corresponding PackageURL will be helpful. |
||
""" | ||
Return a ``golang_purl`` from a standard go import string | ||
TG1999 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``go_package``. | ||
""" | ||
|
||
serializer_class = GoLangPurlSerializer | ||
|
||
def get_view_name(self): | ||
return "GoLang purl" | ||
|
||
def list(self, request): | ||
serializer = self.serializer_class(data=request.query_params) | ||
response = {} | ||
|
||
if not serializer.is_valid(): | ||
return Response( | ||
{"errors": serializer.errors}, status=status.HTTP_400_BAD_REQUEST | ||
) | ||
|
||
validated_data = serializer.validated_data | ||
go_import = validated_data.get("go_package") | ||
purl = get_golang_purl(go_import) | ||
response["golang_purl"] = purl | ||
TG1999 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
serializer = GoLangPurlResponseSerializer( | ||
response, context={"request": request} | ||
) | ||
return Response(serializer.data) | ||
|
||
api_to_purl_router = routers.DefaultRouter() | ||
api_to_purl_router.register("go", GolangPurlViewSet, "go") |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK,
github.com/gorilla/[email protected]
is not a valid import statement.Does Go allow specifying a particular package version using an
@
symbol in an import statement?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, not a go import https://github.com/moby/moby/blob/6c10086976d07d4746e03dcfd188972a2f07e1c9/vendor.mod#L51 but
*.mod
files does have version representation like this? should I change the code in packageurl-python to accept this kind of inputs as well ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the code to also accept this would make sense. With proper documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, see also https://stackoverflow.com/questions/24855081/how-do-i-import-a-specific-version-of-a-package-using-go-get and in particular the reference to http://labix.org/gopkg.in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it makes sense to support getting PURLs from both Go import and Go Manifest.
However, I'm not sure if we want to support obtaining PURLs from Go dependency management commands like...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@keshav-space so should we throw an error when we encounter any package like this ? when there is "@" in package, we should error out ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a PR here https://github.com/package-url/packageurl-python/pull/148/files, please have a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't support them in packageurl-python, then we should raise an error here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is all OK and handled in the packageurl library. And we do not support the @ notation from a "go get"