diff --git a/CHANGES/2480.deprecation b/CHANGES/2480.deprecation new file mode 100644 index 0000000000..a0ed539f75 --- /dev/null +++ b/CHANGES/2480.deprecation @@ -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). diff --git a/pulp_rpm/app/migrations/0056_rpmpublication_checksum_type_and_more.py b/pulp_rpm/app/migrations/0056_rpmpublication_checksum_type_and_more.py new file mode 100644 index 0000000000..9e99c67ec2 --- /dev/null +++ b/pulp_rpm/app/migrations/0056_rpmpublication_checksum_type_and_more.py @@ -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), + ), + ] diff --git a/pulp_rpm/app/models/repository.py b/pulp_rpm/app/models/repository.py index 072a63e999..aefc499f6c 100644 --- a/pulp_rpm/app/models/repository.py +++ b/pulp_rpm/app/models/repository.py @@ -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) @@ -249,6 +250,12 @@ 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, @@ -256,6 +263,7 @@ def on_new_version(self, version): 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, @@ -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) diff --git a/pulp_rpm/app/serializers/repository.py b/pulp_rpm/app/serializers/repository.py index b8f46f768e..70807d8e1b 100644 --- a/pulp_rpm/app/serializers/repository.py +++ b/pulp_rpm/app/serializers/repository.py @@ -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, @@ -115,7 +121,7 @@ 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] @@ -123,6 +129,20 @@ def validate(self, data): ): 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( @@ -170,6 +190,7 @@ class Meta: "autopublish", "metadata_signing_service", "retain_package_versions", + "checksum_type", "metadata_checksum_type", "package_checksum_type", "gpgcheck", @@ -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, ) @@ -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( @@ -320,6 +361,7 @@ def validate(self, data): class Meta: fields = PublicationSerializer.Meta.fields + ( + "checksum_type", "metadata_checksum_type", "package_checksum_type", "gpgcheck", diff --git a/pulp_rpm/app/viewsets/repository.py b/pulp_rpm/app/viewsets/repository.py index 53df55206e..cb5e361b89 100644 --- a/pulp_rpm/app/viewsets/repository.py +++ b/pulp_rpm/app/viewsets/repository.py @@ -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 ) @@ -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