Created
November 5, 2019 21:13
-
-
Save bmbouter/81be284e6296c541ef9c4a0efc9b304f to your computer and use it in GitHub Desktop.
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
# Here's the core diff adding an optional param. Note that if plugin_context_manager is passed in, | |
# it's already been fully configured by the plugin writer. | |
diff --git a/pulpcore/plugin/serializers/content.py b/pulpcore/plugin/serializers/content.py | |
index f2bc5d47e..72e116b56 100644 | |
--- a/pulpcore/plugin/serializers/content.py | |
+++ b/pulpcore/plugin/serializers/content.py | |
@@ -77,7 +77,7 @@ class SingleArtifactContentUploadSerializer(SingleArtifactContentSerializer): | |
""" | |
return data | |
- def create(self, validated_data): | |
+ def create(self, validated_data, plugin_context_manager=None): | |
"""Save the GenericContent unit. | |
This must be used inside a task that locks on the Artifact and if given, the repository. | |
""" | |
@@ -90,7 +90,11 @@ class SingleArtifactContentUploadSerializer(SingleArtifactContentSerializer): | |
# create new repo version with uploaded package | |
with RepositoryVersion.create(repository) as new_version: | |
- new_version.add_content(content_to_add) | |
+ if plugin_context_manager: | |
+ with plugin_context_manager: | |
+ new_version.add_content(content_to_add) | |
+ else: | |
+ new_version.add_content(content_to_add) | |
return content | |
class Meta(SingleArtifactContentSerializer.Meta): | |
# And here's a pulp_file example showing it's usage. Plugins that require no extra opportunity for | |
# modification/validation would leave it unset and wouldn't have to implement this change in their plugin at all. | |
diff --git a/pulp_file/app/serializers.py b/pulp_file/app/serializers.py | |
index 5926cf3..0e138b4 100644 | |
--- a/pulp_file/app/serializers.py | |
+++ b/pulp_file/app/serializers.py | |
@@ -13,6 +13,7 @@ from pulpcore.plugin.serializers import ( | |
) | |
from .models import FileContent, FileDistribution, FileRemote, FilePublication | |
+from pulp_file.app.context_managers import RelativePathFixer | |
class FileContentSerializer(SingleArtifactContentUploadSerializer, ContentChecksumSerializer): | |
@@ -40,6 +41,14 @@ class FileContentSerializer(SingleArtifactContentUploadSerializer, ContentChecks | |
return data | |
+ def create(self, validated_data): | |
+ """ | |
+ This only serves to instantiate and configure the context manager and pass it along to core | |
+ """ | |
+ user_data_I_need = validated_data['thing1'] | |
+ plugin_context_manager = RelativePathFixer(user_data_I_need) | |
+ super().create(validated_data, plugin_context_manager=plugin_context_manager) | |
+ | |
class Meta: | |
fields = ( | |
SingleArtifactContentUploadSerializer.Meta.fields |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment