diff --git a/CHANGES/2902.feature b/CHANGES/2902.feature new file mode 100644 index 0000000000..55abd39441 --- /dev/null +++ b/CHANGES/2902.feature @@ -0,0 +1 @@ +Added new json field repo_config that can be used to configure .repo file diff --git a/CHANGES/2903.feature b/CHANGES/2903.feature new file mode 100644 index 0000000000..55abd39441 --- /dev/null +++ b/CHANGES/2903.feature @@ -0,0 +1 @@ +Added new json field repo_config that can be used to configure .repo file diff --git a/pulp_rpm/app/migrations/0054_remove_rpmpublication_gpgcheck_and_more.py b/pulp_rpm/app/migrations/0054_remove_rpmpublication_gpgcheck_and_more.py new file mode 100644 index 0000000000..fcdafb74ac --- /dev/null +++ b/pulp_rpm/app/migrations/0054_remove_rpmpublication_gpgcheck_and_more.py @@ -0,0 +1,39 @@ +# Generated by Django 4.2.4 on 2023-09-08 14:45 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("rpm", "0053_rpmdistribution_generate_repo_config"), + ] + + operations = [ + migrations.RemoveField( + model_name="rpmpublication", + name="gpgcheck", + ), + migrations.RemoveField( + model_name="rpmpublication", + name="repo_gpgcheck", + ), + migrations.RemoveField( + model_name="rpmrepository", + name="gpgcheck", + ), + migrations.RemoveField( + model_name="rpmrepository", + name="repo_gpgcheck", + ), + migrations.AddField( + model_name="rpmpublication", + name="repo_config", + field=models.JSONField(default=dict), + ), + migrations.AddField( + model_name="rpmrepository", + name="repo_config", + field=models.JSONField(default=dict), + ), + ] diff --git a/pulp_rpm/app/models/repository.py b/pulp_rpm/app/models/repository.py index 7824ef5e3a..a5bf4a810b 100644 --- a/pulp_rpm/app/models/repository.py +++ b/pulp_rpm/app/models/repository.py @@ -198,12 +198,8 @@ class RpmRepository(Repository, AutoAddObjPermsMixin): The name of a checksum type to use for metadata when generating metadata. package_checksum_type (String): The name of a default checksum type to use for packages when generating metadata. - gpgcheck (Integer): - 1 or 0 corresponding to whether gpgcheck should be enabled in the generated .repo file. - repo_gpgcheck (Integer): - 1 or 0 corresponding to whether repo_gpgcheck should be enabled in the generated - .repo file. sqlite_metadata (Boolean): Whether to generate sqlite metadata files on publish. + repo_config (JSON): repo configuration that will be served by distribution """ TYPE = "rpm" @@ -221,7 +217,6 @@ class RpmRepository(Repository, AutoAddObjPermsMixin): ModulemdObsolete, ] REMOTE_TYPES = [RpmRemote, UlnRemote] - GPGCHECK_CHOICES = [(0, 0), (1, 1)] metadata_signing_service = models.ForeignKey( AsciiArmoredDetachedSigningService, on_delete=models.SET_NULL, null=True @@ -233,9 +228,8 @@ class RpmRepository(Repository, AutoAddObjPermsMixin): autopublish = models.BooleanField(default=False) metadata_checksum_type = models.TextField(null=True, choices=CHECKSUM_CHOICES) package_checksum_type = models.TextField(null=True, choices=CHECKSUM_CHOICES) - gpgcheck = models.IntegerField(default=0, choices=GPGCHECK_CHOICES) - repo_gpgcheck = models.IntegerField(default=0, choices=GPGCHECK_CHOICES) sqlite_metadata = models.BooleanField(default=False) + repo_config = models.JSONField(default=dict) def on_new_version(self, version): """ @@ -258,13 +252,13 @@ def on_new_version(self, version): if self.autopublish: tasks.publish( repository_version_pk=version.pk, - gpgcheck_options={"gpgcheck": self.gpgcheck, "repo_gpgcheck": self.repo_gpgcheck}, metadata_signing_service=self.metadata_signing_service, checksum_types={ "metadata": self.metadata_checksum_type, "package": self.package_checksum_type, }, sqlite_metadata=self.sqlite_metadata, + repo_config=self.repo_config, ) @staticmethod @@ -423,14 +417,11 @@ class RpmPublication(Publication, AutoAddObjPermsMixin): Publication for "rpm" content. """ - GPGCHECK_CHOICES = [(0, 0), (1, 1)] - TYPE = "rpm" metadata_checksum_type = models.TextField(choices=CHECKSUM_CHOICES) package_checksum_type = models.TextField(choices=CHECKSUM_CHOICES) - gpgcheck = models.IntegerField(default=0, choices=GPGCHECK_CHOICES) - repo_gpgcheck = models.IntegerField(default=0, choices=GPGCHECK_CHOICES) sqlite_metadata = models.BooleanField(default=False) + repo_config = models.JSONField(default=dict) class Meta: default_related_name = "%(app_label)s_%(model_name)s" @@ -474,16 +465,27 @@ def content_handler(self, path): self.base_path, ) ) + repo_config = publication.repo_config + repo_config.pop("name", None) + repo_config.pop("baseurl", None) val = textwrap.dedent( f"""\ [{re.sub(self.INVALID_REPO_ID_CHARS, "", self.name)}] name={self.name} - enabled=1 baseurl={base_url} - gpgcheck={publication.gpgcheck} - repo_gpgcheck={publication.repo_gpgcheck} """ ) + for k, v in repo_config.items(): + val += f"{k}={v}\n" + + if "repo_gpgcheck" not in repo_config: + val += "repo_gpgcheck=0\n" + + if "gpgcheck" not in repo_config: + val += "gpgcheck=0\n" + + if "enabled" not in repo_config: + val += "enabled=1\n" signing_service = repository.metadata_signing_service if signing_service: diff --git a/pulp_rpm/app/serializers/repository.py b/pulp_rpm/app/serializers/repository.py index 2883b6b069..b199bffa8c 100644 --- a/pulp_rpm/app/serializers/repository.py +++ b/pulp_rpm/app/serializers/repository.py @@ -79,26 +79,7 @@ class RpmRepositorySerializer(RepositorySerializer): required=False, allow_null=True, ) - gpgcheck = serializers.IntegerField( - max_value=1, - min_value=0, - default=0, - required=False, - help_text=_( - "An option specifying whether a client should perform " - "a GPG signature check on packages." - ), - ) - repo_gpgcheck = serializers.IntegerField( - max_value=1, - min_value=0, - default=0, - required=False, - help_text=_( - "An option specifying whether a client should perform " - "a GPG signature check on the repodata." - ), - ) + sqlite_metadata = serializers.BooleanField( default=False, required=False, @@ -106,6 +87,10 @@ class RpmRepositorySerializer(RepositorySerializer): "DEPRECATED: An option specifying whether Pulp should generate SQLite metadata." ), ) + repo_config = serializers.JSONField( + required=False, + help_text=_("A JSON document describing config.repo file"), + ) def validate(self, data): """Validate data.""" @@ -127,9 +112,8 @@ class Meta: "retain_package_versions", "metadata_checksum_type", "package_checksum_type", - "gpgcheck", - "repo_gpgcheck", "sqlite_metadata", + "repo_config", ) model = RpmRepository @@ -219,24 +203,6 @@ class RpmPublicationSerializer(PublicationSerializer): choices=CHECKSUM_CHOICES, required=False, ) - gpgcheck = serializers.IntegerField( - max_value=1, - min_value=0, - required=False, - help_text=_( - "An option specifying whether a client should perform " - "a GPG signature check on packages." - ), - ) - repo_gpgcheck = serializers.IntegerField( - max_value=1, - min_value=0, - required=False, - help_text=_( - "An option specifying whether a client should perform " - "a GPG signature check on the repodata." - ), - ) sqlite_metadata = serializers.BooleanField( default=False, required=False, @@ -245,6 +211,11 @@ class RpmPublicationSerializer(PublicationSerializer): ), ) + repo_config = serializers.JSONField( + required=False, + help_text=_("A JSON document describing config.repo file"), + ) + def validate(self, data): """Validate data.""" if ( @@ -262,9 +233,8 @@ class Meta: fields = PublicationSerializer.Meta.fields + ( "metadata_checksum_type", "package_checksum_type", - "gpgcheck", - "repo_gpgcheck", "sqlite_metadata", + "repo_config", ) model = RpmPublication diff --git a/pulp_rpm/app/tasks/publishing.py b/pulp_rpm/app/tasks/publishing.py index 34c1c00d2c..17d8829d76 100644 --- a/pulp_rpm/app/tasks/publishing.py +++ b/pulp_rpm/app/tasks/publishing.py @@ -320,21 +320,21 @@ def cr_checksum_type_from_string(checksum_type): def publish( repository_version_pk, - gpgcheck_options=None, metadata_signing_service=None, checksum_types=None, sqlite_metadata=False, + repo_config=None, ): """ Create a Publication based on a RepositoryVersion. Args: repository_version_pk (str): Create a publication from this repository version. - gpgcheck_options (dict): GPG signature check options. metadata_signing_service (pulpcore.app.models.AsciiArmoredDetachedSigningService): A reference to an associated signing service. checksum_types (dict): Checksum types for metadata and packages. sqlite_metadata (bool): Whether to generate metadata files in sqlite format. + repo_config (JSON): repo config that will be served by distribution """ repository_version = RepositoryVersion.objects.get(pk=repository_version_pk) @@ -361,13 +361,11 @@ def publish( checksum_types.get("package") or publication.metadata_checksum_type ) - if gpgcheck_options is not None: - publication.gpgcheck = gpgcheck_options.get("gpgcheck") - publication.repo_gpgcheck = gpgcheck_options.get("repo_gpgcheck") - if sqlite_metadata: publication.sqlite_metadata = True + publication.repo_config = repo_config + publication_data = PublicationData(publication) publication_data.populate() diff --git a/pulp_rpm/app/tasks/synchronizing.py b/pulp_rpm/app/tasks/synchronizing.py index 3375f9c691..30b04824b8 100644 --- a/pulp_rpm/app/tasks/synchronizing.py +++ b/pulp_rpm/app/tasks/synchronizing.py @@ -158,8 +158,7 @@ def add_metadata_to_publication(publication, version, prefix=""): publication.package_checksum_type = CHECKSUM_TYPES.UNKNOWN publication.metadata_checksum_type = CHECKSUM_TYPES.UNKNOWN - publication.gpgcheck = 0 - publication.repo_gpgcheck = has_repomd_signature + publication.repo_config = {"repo_gpgcheck": has_repomd_signature, "gpgcheck": 0} publication.sqlite_metadata = has_sqlite for relative_path, metadata_file_path in repo_metadata_files.items(): diff --git a/pulp_rpm/app/viewsets/repository.py b/pulp_rpm/app/viewsets/repository.py index 3f555dfc2c..f8cfeed9b0 100644 --- a/pulp_rpm/app/viewsets/repository.py +++ b/pulp_rpm/app/viewsets/repository.py @@ -547,10 +547,7 @@ def create(self, request): metadata=metadata_checksum_type, package=package_checksum_type, ) - gpgcheck_options = dict( - gpgcheck=serializer.validated_data.get("gpgcheck", repository.gpgcheck), - repo_gpgcheck=serializer.validated_data.get("repo_gpgcheck", repository.repo_gpgcheck), - ) + repo_config = serializer.validated_data.get("repo_config", repository.repo_config) sqlite_metadata = serializer.validated_data.get( "sqlite_metadata", repository.sqlite_metadata ) @@ -572,7 +569,7 @@ def create(self, request): "repository_version_pk": repository_version.pk, "metadata_signing_service": signing_service_pk, "checksum_types": checksum_types, - "gpgcheck_options": gpgcheck_options, + "repo_config": repo_config, "sqlite_metadata": sqlite_metadata, }, )