Skip to content

Commit

Permalink
Expose the sha256 for source package dsc files
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
daviddavis committed Oct 7, 2024
1 parent ccc0d82 commit b714236
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/+add-dsc-sha256.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expose a sha256 column for source packages that contains the digest of the dsc file.
5 changes: 5 additions & 0 deletions pulp_deb/app/models/content/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pulp_deb/app/serializers/content_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1245,6 +1246,7 @@ class Meta:
fields = MultipleArtifactContentSerializer.Meta.fields + (
"artifact",
"relative_path",
"sha256",
"format",
"source",
"binary",
Expand Down
2 changes: 1 addition & 1 deletion pulp_deb/app/viewsets/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b714236

Please sign in to comment.