From 3817bfbf6cfe4fda702e8cb6df82b28a9504333b Mon Sep 17 00:00:00 2001 From: David Davis Date: Mon, 7 Oct 2024 07:53:09 -0400 Subject: [PATCH] Expose the sha256 for dsc files We'd like to be able to have a sha256 column for Source Packages like we do for packages. This would save us an extra call to the artifact endpoint. [noissue] --- CHANGES/+add-dsc-sha256.feature | 1 + pulp_deb/app/models/content/content.py | 5 +++++ pulp_deb/app/serializers/content_serializers.py | 2 ++ pulp_deb/app/viewsets/content.py | 2 +- 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 CHANGES/+add-dsc-sha256.feature diff --git a/CHANGES/+add-dsc-sha256.feature b/CHANGES/+add-dsc-sha256.feature new file mode 100644 index 000000000..f3a2705d9 --- /dev/null +++ b/CHANGES/+add-dsc-sha256.feature @@ -0,0 +1 @@ +Expose a sha256 column for source packages that contains the digest of the dsc file. diff --git a/pulp_deb/app/models/content/content.py b/pulp_deb/app/models/content/content.py index 04344907e..4957fd4c4 100644 --- a/pulp_deb/app/models/content/content.py +++ b/pulp_deb/app/models/content/content.py @@ -197,6 +197,11 @@ def __init__(self, *args, **kwargs): kwargs.pop(kw) super().__init__(*args, **kwargs) + @property + def sha256(self): + """Return the sha256 of the dsc file.""" + return self.contentartifact_set.get(relative_path=self.relative_path).artifact.sha256 + def derived_dsc_filename(self): """Print a nice name for the Dsc file.""" return "{}_{}.{}".format(self.source, self.version, self.SUFFIX) diff --git a/pulp_deb/app/serializers/content_serializers.py b/pulp_deb/app/serializers/content_serializers.py index 0f357a07e..d1ed21c2a 100644 --- a/pulp_deb/app/serializers/content_serializers.py +++ b/pulp_deb/app/serializers/content_serializers.py @@ -1146,6 +1146,7 @@ class SourcePackageSerializer(MultipleArtifactContentSerializer): ), required=False, ) + sha256 = CharField(help_text=_("sha256 digest of the dsc file."), read_only=True) format = CharField(read_only=True) source = CharField(read_only=True) binary = CharField(read_only=True) @@ -1245,6 +1246,7 @@ class Meta: fields = MultipleArtifactContentSerializer.Meta.fields + ( "artifact", "relative_path", + "sha256", "format", "source", "binary", diff --git a/pulp_deb/app/viewsets/content.py b/pulp_deb/app/viewsets/content.py index 267d3a1f6..ee4ef4a75 100644 --- a/pulp_deb/app/viewsets/content.py +++ b/pulp_deb/app/viewsets/content.py @@ -596,7 +596,7 @@ class SourcePackageViewSet(SingleArtifactContentUploadViewSet): """ endpoint_name = "source_packages" - queryset = models.SourcePackage.objects.prefetch_related("_artifacts") + queryset = models.SourcePackage.objects.prefetch_related("_artifacts", "contentartifact_set") serializer_class = serializers.SourcePackageSerializer filterset_class = SourcePackageFilter