-
Notifications
You must be signed in to change notification settings - Fork 81
Add more fields and validation to twine upload endpoint #995
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
Open
gerrod3
wants to merge
1
commit into
pulp:main
Choose a base branch
from
gerrod3:more-twine-upload-fields
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 hidden or 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 |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| from gettext import gettext as _ | ||
|
|
||
| from rest_framework import serializers | ||
| from pulp_python.app.utils import DIST_EXTENSIONS | ||
| from pulp_python.app.utils import DIST_EXTENSIONS, SUPPORTED_METADATA_VERSIONS | ||
| from pulpcore.plugin.models import Artifact | ||
| from pulpcore.plugin.util import get_domain | ||
| from django.db.utils import IntegrityError | ||
|
|
@@ -54,6 +54,22 @@ class PackageUploadSerializer(serializers.Serializer): | |
| min_length=64, | ||
| max_length=64, | ||
| ) | ||
| protocol_version = serializers.ChoiceField( | ||
| help_text=_("Protocol version to use for the upload. Only version 1 is supported."), | ||
| required=False, | ||
| choices=(1,), | ||
| default=1, | ||
| ) | ||
| filetype = serializers.ChoiceField( | ||
| help_text=_("Type of artifact to upload."), | ||
| required=False, | ||
| choices=("bdist_wheel", "sdist"), | ||
| ) | ||
| metadata_version = serializers.ChoiceField( | ||
| help_text=_("Metadata version of the uploaded package."), | ||
| required=False, | ||
| choices=SUPPORTED_METADATA_VERSIONS, | ||
| ) | ||
|
|
||
| def validate(self, data): | ||
| """Validates the request.""" | ||
|
|
@@ -63,14 +79,26 @@ def validate(self, data): | |
| file = data.get("content") | ||
| for ext, packagetype in DIST_EXTENSIONS.items(): | ||
| if file.name.endswith(ext): | ||
| if filetype := data.get("filetype"): | ||
| if filetype != packagetype: | ||
|
Comment on lines
+82
to
+83
Contributor
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. Maybe |
||
| raise serializers.ValidationError( | ||
| { | ||
| "filetype": _( | ||
| "filetype {} does not match found filetype {} for file {}" | ||
jobselko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ).format(filetype, packagetype, file.name) | ||
| } | ||
| ) | ||
| break | ||
| else: | ||
| raise serializers.ValidationError( | ||
| _( | ||
| "Extension on {} is not a valid python extension " | ||
| "(.whl, .exe, .egg, .tar.gz, .tar.bz2, .zip)" | ||
| ).format(file.name) | ||
| { | ||
| "content": _( | ||
| "Extension on {} is not a valid python extension " | ||
| "(.whl, .exe, .egg, .tar.gz, .tar.bz2, .zip)" | ||
| ).format(file.name) | ||
| } | ||
| ) | ||
|
|
||
| sha256 = data.get("sha256_digest") | ||
| digests = {"sha256": sha256} if sha256 else None | ||
| artifact = Artifact.init_and_validate(file, expected_digests=digests) | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
edit: maybe I'm misunderstanding, I suppose you mention that the values do come from the uploaded artifact, but the RPM plugin also does so and doesn't add any of the metadata to the upload serializer, so this is different than what I'm familiar with.
I'm confused about the fact that all of it seems to be optional. If it's all optional than why allow the user to specify in the first place (maybe these are all just gripes with the API they've chosen and not with the fact that Pulp needs to implement it)
Is it just the case that twine provides all this information on uploads and the API (including e.g. warehouse) is meant to just trust it unconditionally, if provided? Or does it get verified? And if it gets verified then against what, and why bother with accepting it if there's a canonical source?
Seems like it would be ideal for most of these details to be parsed from package metadata instead of provided alongside the upload? (though IIRC that was briefly discussed earlier, I guess my point is that if we add it now would it not become useless should metadata later be parsed directly from the package). But again maybe this is just complaining about the API
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.
Yeah, maybe I should remove them. Reading the PyPI code (https://github.com/pypi/warehouse/blob/117eafc3739f738a2c29fbadbb858bf502ba1ff0/warehouse/forklift/legacy.py#L618-L623) it seems they trust all the metadata that is posted in the request, but we have always been extracting the metadata from the file so these fields are kind of useless.
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.
So, what is the resolution, stay or remove?
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.
They're gone, look at the latest push.