Skip to content

Commit

Permalink
draft/wip "omitting" artifact from serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hyagi committed Apr 26, 2024
1 parent 95cc460 commit 30eedfb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
25 changes: 24 additions & 1 deletion pulp_container/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re

from django.core.validators import URLValidator
from drf_spectacular.utils import extend_schema_field, extend_schema, extend_schema_serializer
from rest_framework import serializers

from pulpcore.plugin.models import (
Expand Down Expand Up @@ -120,7 +121,9 @@ class Meta:
)
model = models.Manifest


@extend_schema_serializer(
exclude_fields=('artifact',)
)
class BlobSerializer(SingleArtifactContentSerializer):
"""
Serializer for Blobs.
Expand All @@ -130,12 +133,32 @@ class BlobSerializer(SingleArtifactContentSerializer):
artifact = SingleContentArtifactField(
help_text=_("Artifact file representing the physical content"), required=False
)

#@extend_schema_field(nullable=True)
@extend_schema_field({'required': False, 'nullable': True})
def get_artifact(self, *args,**kwargs):
return self.artifact

@extend_schema_field({'required': False, 'nullable': True})
def list_artifact(self, *args,**kwargs):
return self.artifact

class Meta:
fields = SingleArtifactContentSerializer.Meta.fields + ("digest",)
model = models.Blob


class ArtifactlessBlobSerializer(NoArtifactContentSerializer):
"""
Serializer for Blobs.
"""

digest = serializers.CharField(help_text="sha256 of the Blob file")

class Meta:
fields = NoArtifactContentSerializer.Meta.fields + ("digest",)
model = models.Blob

class ManifestSignatureSerializer(NoArtifactContentSerializer):
"""
Serializer for image manifest signatures.
Expand Down
2 changes: 1 addition & 1 deletion pulp_container/app/tasks/sync_stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ async def _get_blob_size_data(self, blob_data, blob_url, is_layer):
response = await downloader.run(extra_data={"headers": V2_ACCEPT_HEADERS})
with open(response.path, "rb") as content_file:
raw_data = content_file.read()
return response.artifact_attributes['size'], raw_data
return response.artifact_attributes.get('size'), raw_data

async def create_signatures(self, man_dc, signature_source):
"""
Expand Down
23 changes: 22 additions & 1 deletion pulp_container/app/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.db.models import Q

from django_filters import CharFilter, MultipleChoiceFilter
from drf_spectacular.utils import extend_schema
from drf_spectacular.utils import extend_schema, extend_schema_view, PolymorphicProxySerializer

from rest_framework import mixins
from rest_framework.decorators import action
Expand Down Expand Up @@ -285,6 +285,27 @@ class ManifestViewSet(ContainerContentQuerySetMixin, ReadOnlyContentViewSet):
}


#@extend_schema_view(
# list=extend_schema(
# request=PolymorphicProxySerializer(
# component_name='Blob',
# serializers=[
# serializers.BlobSerializer, serializers.ArtifactlessBlobSerializer,
# ],
# resource_type_field_name='artifact',
# )
# )
#)
#@extend_schema_view(list=extend_schema(fields={'artifact': {'nullable': True, 'required': False}}))
#@extend_schema_view(operation={'fields':{'artifact': {'nullable': True, 'required': False}}})
#@extend_schema_view(list=extend_schema(
# responses={
# 200: PolymorphicProxySerializer(
# component_name='Blob',
# serializers=[serializers.BlobSerializer, serializers.ArtifactlessBlobSerializer],
# resource_type_field_name='artifact',
# ),
# }))
class BlobViewSet(ContainerContentQuerySetMixin, ReadOnlyContentViewSet):
"""
ViewSet for Blobs.
Expand Down

0 comments on commit 30eedfb

Please sign in to comment.