Skip to content

Commit

Permalink
Deprecate 'package_checksum_type' and 'metadata_checksum_type'
Browse files Browse the repository at this point in the history
closes #2480
  • Loading branch information
dralley committed Nov 7, 2023
1 parent 88bf3fc commit f2b7ce1
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES/2480.deprecation
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Deprecated the 'package_checksum_type' and 'metadata_checksum_type' options on the `RpmRepository`
and `RpmPublication` models. A 'checksum_type' argument will be provided instead, which will
control both settings (but they will no longer be individually controllable).
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.5 on 2023-11-07 03:51

from django.db import migrations, models
from django.db.models import F


def set_publication_checksum(apps, schema_editor):
RpmPublication = apps.get_model("rpm", "RpmPublication")
RpmPublication.objects.update(checksum_type=F("metadata_checksum_type"))


class Migration(migrations.Migration):

dependencies = [
('rpm', '0055_add_repo_config_field'),
]

operations = [
migrations.AddField(
model_name='rpmpublication',
name='checksum_type',
field=models.TextField(choices=[('unknown', 'unknown'), ('md5', 'md5'), ('sha1', 'sha1'), ('sha1', 'sha1'), ('sha224', 'sha224'), ('sha256', 'sha256'), ('sha384', 'sha384'), ('sha512', 'sha512')], null=True),
),
migrations.RunPython(set_publication_checksum),
migrations.AlterField(
model_name='rpmpublication',
name='checksum_type',
field=models.TextField(choices=[('unknown', 'unknown'), ('md5', 'md5'), ('sha1', 'sha1'), ('sha1', 'sha1'), ('sha224', 'sha224'), ('sha256', 'sha256'), ('sha384', 'sha384'), ('sha512', 'sha512')]),
),
migrations.AddField(
model_name='rpmrepository',
name='checksum_type',
field=models.TextField(choices=[('unknown', 'unknown'), ('md5', 'md5'), ('sha1', 'sha1'), ('sha1', 'sha1'), ('sha224', 'sha224'), ('sha256', 'sha256'), ('sha384', 'sha384'), ('sha512', 'sha512')], null=True),
),
]
9 changes: 9 additions & 0 deletions pulp_rpm/app/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class RpmRepository(Repository, AutoAddObjPermsMixin):
retain_package_versions = models.PositiveIntegerField(default=0)

autopublish = models.BooleanField(default=False)
checksum_type = models.TextField(null=True, choices=CHECKSUM_CHOICES)
metadata_checksum_type = models.TextField(null=True, choices=CHECKSUM_CHOICES)
package_checksum_type = models.TextField(null=True, choices=CHECKSUM_CHOICES)
sqlite_metadata = models.BooleanField(default=False)
Expand All @@ -249,13 +250,20 @@ def on_new_version(self, version):
"of pulp_rpm. See https://tinyurl.com/sqlite-removal for more details"
)

if self.metadata_checksum_type or self.package_checksum_type:
getLogger("pulp_rpm.deprecation").info(
"Support for setting 'package_checksum_type' and 'metadata_checksum_type ",
" will be removed from a future release of pulp_rpm, replaced by 'checksum_type' ",
)

if self.autopublish:
tasks.publish(
repository_version_pk=version.pk,
metadata_signing_service=self.metadata_signing_service,
checksum_types={
"metadata": self.metadata_checksum_type,
"package": self.package_checksum_type,
"general": self.checksum_type,
},
sqlite_metadata=self.sqlite_metadata,
repo_config=self.repo_config,
Expand Down Expand Up @@ -422,6 +430,7 @@ class RpmPublication(Publication, AutoAddObjPermsMixin):
"""

TYPE = "rpm"
checksum_type = models.TextField(choices=CHECKSUM_CHOICES)
metadata_checksum_type = models.TextField(choices=CHECKSUM_CHOICES)
package_checksum_type = models.TextField(choices=CHECKSUM_CHOICES)
sqlite_metadata = models.BooleanField(default=False)
Expand Down
52 changes: 47 additions & 5 deletions pulp_rpm/app/serializers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,20 @@ class RpmRepositorySerializer(RepositorySerializer):
min_value=0,
required=False,
)
checksum_type = serializers.ChoiceField(
help_text=_("The preferred checksum type during repo publish."),
choices=CHECKSUM_CHOICES,
required=False,
allow_null=True,
)
metadata_checksum_type = serializers.ChoiceField(
help_text=_("The checksum type for metadata."),
help_text=_("DEPRECATED: use CHECKSUM_TYPE instead."),
choices=CHECKSUM_CHOICES,
required=False,
allow_null=True,
)
package_checksum_type = serializers.ChoiceField(
help_text=_("The checksum type for packages."),
help_text=_("DEPRECATED: use CHECKSUM_TYPE instead."),
choices=CHECKSUM_CHOICES,
required=False,
allow_null=True,
Expand Down Expand Up @@ -115,14 +121,28 @@ class RpmRepositorySerializer(RepositorySerializer):

def validate(self, data):
"""Validate data."""
for field in ("metadata_checksum_type", "package_checksum_type"):
for field in ("checksum_type", "metadata_checksum_type", "package_checksum_type"):
if (
field in data
and data[field]
and data[field] not in settings.ALLOWED_CONTENT_CHECKSUMS
):
raise serializers.ValidationError({field: _(ALLOWED_CHECKSUM_ERROR_MSG)})

if data.get("package_checksum_type") or data.get("metadata_checksum_type"):
logging.getLogger("pulp_rpm.deprecation").info(
"Support for '*_checksum_type' options will be removed from a future release "
"of pulp_rpm."
)
if data.get("checksum_type"):
raise serializers.ValidationError(
_(
"Cannot use '*_checksum_type' options and 'checksum_type' options "
"simultaneously. The 'package_checksum_type' and 'metadata_checksum_type' "
"options are deprecated, please use 'checksum_type' only."
)
)

validated_data = super().validate(data)
if (data.get("gpgcheck") or data.get("repo_gpgcheck")) and data.get("repo_config"):
raise serializers.ValidationError(
Expand Down Expand Up @@ -170,6 +190,7 @@ class Meta:
"autopublish",
"metadata_signing_service",
"retain_package_versions",
"checksum_type",
"metadata_checksum_type",
"package_checksum_type",
"gpgcheck",
Expand Down Expand Up @@ -256,12 +277,17 @@ class RpmPublicationSerializer(PublicationSerializer):
"""

metadata_checksum_type = serializers.ChoiceField(
help_text=_("The checksum type for metadata."),
help_text=_("DEPRECATED: The checksum type for metadata."),
choices=CHECKSUM_CHOICES,
required=False,
)
package_checksum_type = serializers.ChoiceField(
help_text=_("The checksum type for packages."),
help_text=_("DEPRECATED: The checksum type for packages."),
choices=CHECKSUM_CHOICES,
required=False,
)
checksum_type = serializers.ChoiceField(
help_text=_("The preferred checksum type used during repo publishes."),
choices=CHECKSUM_CHOICES,
required=False,
)
Expand Down Expand Up @@ -307,6 +333,21 @@ def validate(self, data):
and data["package_checksum_type"] not in settings.ALLOWED_CONTENT_CHECKSUMS
):
raise serializers.ValidationError(_(ALLOWED_CHECKSUM_ERROR_MSG))

if data.get("package_checksum_type") or data.get("metadata_checksum_type"):
logging.getLogger("pulp_rpm.deprecation").info(
"Support for '*_checksum_type' options will be removed from a future release "
"of pulp_rpm."
)
if data.get("checksum_type"):
raise serializers.ValidationError(
_(
"Cannot use '*_checksum_type' options and 'checksum_type' options "
"simultaneously. The 'package_checksum_type' and 'metadata_checksum_type' "
"options are deprecated, please use 'checksum_type' only."
)
)

validated_data = super().validate(data)
if (data.get("gpgcheck") or data.get("repo_gpgcheck")) and data.get("repo_config"):
raise serializers.ValidationError(
Expand All @@ -320,6 +361,7 @@ def validate(self, data):

class Meta:
fields = PublicationSerializer.Meta.fields + (
"checksum_type",
"metadata_checksum_type",
"package_checksum_type",
"gpgcheck",
Expand Down
2 changes: 2 additions & 0 deletions pulp_rpm/app/viewsets/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ def create(self, request):
repository_version = serializer.validated_data.get("repository_version")
repository = RpmRepository.objects.get(pk=repository_version.repository.pk)

checksum_type = serializer.validated_data.get("checksum_type", repository.checksum_type)
metadata_checksum_type = serializer.validated_data.get(
"metadata_checksum_type", repository.metadata_checksum_type
)
Expand All @@ -546,6 +547,7 @@ def create(self, request):
checksum_types = dict(
metadata=metadata_checksum_type,
package=package_checksum_type,
general=checksum_type,
)
# gpg options are deprecated in favour of repo_config
# acting as shim layer between old and new api
Expand Down

0 comments on commit f2b7ce1

Please sign in to comment.