diff --git a/CHANGES/272.feature b/CHANGES/272.feature new file mode 100644 index 0000000..0b91bba --- /dev/null +++ b/CHANGES/272.feature @@ -0,0 +1 @@ +Added cli options for configuring excluded package metadata fields on remotes, repositories and publications diff --git a/pulp-glue-deb/src/pulp_glue/deb/context.py b/pulp-glue-deb/src/pulp_glue/deb/context.py index f0e26ab..db26d11 100644 --- a/pulp-glue-deb/src/pulp_glue/deb/context.py +++ b/pulp-glue-deb/src/pulp_glue/deb/context.py @@ -15,6 +15,21 @@ _ = translation.gettext +def _tuple_to_list(field_name: str, body: EntityDefinition) -> None: + """Convert a repeated cli option tuple to an API list""" + if field_name not in body: + return + + value = body[field_name] + if not isinstance(value, tuple): + return + + if not value: + body.pop(field_name) + else: + body[field_name] = [item for item in value if item] + + class PulpDebGenericContentContext(PulpContentContext): ENTITY = "deb generic content" ENTITIES = "deb generic contents" @@ -137,6 +152,7 @@ class PulpAptPublicationContext(PulpEntityContext): def preprocess_entity(self, body: EntityDefinition, partial: bool = False) -> EntityDefinition: body = super().preprocess_entity(body) + _tuple_to_list("excluded_package_metadata_fields", body) version = body.pop("version", None) if version is not None: repository_href = body.pop("repository") @@ -145,7 +161,12 @@ def preprocess_entity(self, body: EntityDefinition, partial: bool = False) -> En class PulpVerbatimPublicationContext(PulpEntityContext): - APT_ONLY: ClassVar[set[str]] = {"simple", "structured", "signing_service"} + APT_ONLY: ClassVar[set[str]] = { + "simple", + "structured", + "signing_service", + "excluded_package_metadata_fields", + } ENTITY = _("verbatim publication") ENTITIES = _("verbatim publications") HREF = "deb_verbatim_publication_href" @@ -199,6 +220,7 @@ def preprocess_entity(self, body: EntityDefinition, partial: bool = False) -> En raise PulpException("Must have at least one distribution for remote.") self.tuple_to_whitespace_separated_string("components", body) self.tuple_to_whitespace_separated_string("architectures", body) + _tuple_to_list("excluded_package_metadata_fields", body) return body @@ -219,3 +241,8 @@ class PulpAptRepositoryContext(PulpRepositoryContext): RESOURCE_TYPE = "apt" VERSION_CONTEXT = PulpAptRepositoryVersionContext CAPABILITIES = {"pulpexport": [PluginRequirement("deb", "2.20.0")]} + + def preprocess_entity(self, body: EntityDefinition, partial: bool = False) -> EntityDefinition: + body = super().preprocess_entity(body) + _tuple_to_list("excluded_package_metadata_fields", body) + return body diff --git a/src/pulpcore/cli/deb/publication.py b/src/pulpcore/cli/deb/publication.py index c1ec546..0bfb488 100644 --- a/src/pulpcore/cli/deb/publication.py +++ b/src/pulpcore/cli/deb/publication.py @@ -87,6 +87,16 @@ def publication(ctx: click.Context, pulp_ctx: PulpCLIContext, /, publication_typ context_table={"deb:apt": PulpSigningServiceContext}, help=_("Apt only: Signing service to use, pass in name or href"), ), + pulp_option( + "--excluded-package-metadata-field", + "excluded_package_metadata_fields", + multiple=True, + help=_( + "Apt only: Custom package metadata field to omit from generated Packages indices. " + "Can be specified multiple times." + ), + needs_plugins=[PluginRequirement("deb", specifier=">=3.11.0")], + ), ] publication.add_command(list_command(decorators=publication_filter_options)) publication.add_command(show_command(decorators=lookup_options)) diff --git a/src/pulpcore/cli/deb/remote.py b/src/pulpcore/cli/deb/remote.py index d3e98ff..cbaae1a 100644 --- a/src/pulpcore/cli/deb/remote.py +++ b/src/pulpcore/cli/deb/remote.py @@ -12,10 +12,12 @@ load_string_callback, name_option, pass_pulp_context, + pulp_option, show_command, update_command, ) +from pulp_glue.common.context import PluginRequirement from pulp_glue.common.i18n import get_translation from pulp_glue.deb.context import PulpAptRemoteContext @@ -63,6 +65,16 @@ def remote(ctx: click.Context, pulp_ctx: PulpCLIContext, /, remote_type: str) -> "Will sync all available if specified once with the empty string." ), ), + pulp_option( + "--excluded-package-metadata-field", + "excluded_package_metadata_fields", + multiple=True, + help=_( + "Custom package metadata field to exclude during sync. " + "Can be specified multiple times. Pass an empty string to clear the list." + ), + needs_plugins=[PluginRequirement("deb", specifier=">=3.11.0")], + ), ] distribution_help = _("Distribution to sync; can be specified multiple times.") diff --git a/src/pulpcore/cli/deb/repository.py b/src/pulpcore/cli/deb/repository.py index 94a136c..d9cf33a 100644 --- a/src/pulpcore/cli/deb/repository.py +++ b/src/pulpcore/cli/deb/repository.py @@ -119,6 +119,16 @@ def repository(ctx: click.Context, pulp_ctx: PulpCLIContext, /, repo_type: str) nested_lookup_options = [repository_href_option, repository_lookup_option] update_options = [ click.option("--description"), + pulp_option( + "--excluded-package-metadata-field", + "excluded_package_metadata_fields", + multiple=True, + help=_( + "Custom package metadata field to exclude by default from structured publications. " + "Can be specified multiple times. Pass an empty string to clear the list." + ), + needs_plugins=[PluginRequirement("deb", specifier=">=3.11.0")], + ), remote_option, # pulp_option( # "--autopublish/--no-autopublish", diff --git a/tests/scripts/pulp_deb/test_deb_remote.sh b/tests/scripts/pulp_deb/test_deb_remote.sh index 2645a47..39dd724 100755 --- a/tests/scripts/pulp_deb/test_deb_remote.sh +++ b/tests/scripts/pulp_deb/test_deb_remote.sh @@ -33,6 +33,20 @@ assert "$(echo "$OUTPUT" | jq -r .components)" == "foo" assert "$(echo "$OUTPUT" | jq -r .architectures)" == "foo" expect_succ pulp deb remote update --name "${ENTITIES_NAME}" +if pulp debug has-plugin --name deb --specifier ">=3.12.0.dev"; then + expect_succ pulp deb remote update --name "${ENTITIES_NAME}" \ + --excluded-package-metadata-field "Phased-Update-Percentage" \ + --excluded-package-metadata-field "X-Test-Field" + expect_succ pulp deb remote show --name "${ENTITIES_NAME}" + assert "$(echo "$OUTPUT" | jq -c .excluded_package_metadata_fields)" == \ + '["Phased-Update-Percentage","X-Test-Field"]' + + expect_succ pulp deb remote update --name "${ENTITIES_NAME}" \ + --excluded-package-metadata-field "" + expect_succ pulp deb remote show --name "${ENTITIES_NAME}" + assert "$(echo "$OUTPUT" | jq -c .excluded_package_metadata_fields)" == '[]' +fi + # Try some possible modifications of the remote's distribution: expect_succ pulp deb remote update --name "${ENTITIES_NAME}" --distribution "bar" expect_succ pulp deb remote show --name "${ENTITIES_NAME}" diff --git a/tests/scripts/pulp_deb/test_deb_sync_publish.sh b/tests/scripts/pulp_deb/test_deb_sync_publish.sh index 8cf3e4e..7cb7003 100755 --- a/tests/scripts/pulp_deb/test_deb_sync_publish.sh +++ b/tests/scripts/pulp_deb/test_deb_sync_publish.sh @@ -19,9 +19,18 @@ expect_succ pulp deb remote create \ --url "$DEB_REMOTE_URL" \ --distribution "$DEB_DISTRIBUTION" -expect_succ pulp deb repository create \ - --name "${ENTITIES_NAME}_repo" \ - --remote "${ENTITIES_NAME}_remote" +if pulp debug has-plugin --name deb --specifier ">=3.12.0.dev"; then + expect_succ pulp deb repository create \ + --name "${ENTITIES_NAME}_repo" \ + --remote "${ENTITIES_NAME}_remote" \ + --excluded-package-metadata-field "Phased-Update-Percentage" + assert "$(echo "$OUTPUT" | jq -c .excluded_package_metadata_fields)" == \ + '["Phased-Update-Percentage"]' +else + expect_succ pulp deb repository create \ + --name "${ENTITIES_NAME}_repo" \ + --remote "${ENTITIES_NAME}_remote" +fi expect_succ pulp deb repository sync \ --name "${ENTITIES_NAME}_repo" @@ -36,9 +45,18 @@ if pulp debug has-plugin --name deb --min-version 2.20.0.dev; then --no-optimize fi -expect_succ pulp deb publication create \ - --repository "${ENTITIES_NAME}_repo" \ - --simple +if pulp debug has-plugin --name deb --specifier ">=3.11.0"; then + expect_succ pulp deb publication create \ + --repository "${ENTITIES_NAME}_repo" \ + --simple \ + --excluded-package-metadata-field "Phased-Update-Percentage" + assert "$(echo "$OUTPUT" | jq -c .excluded_package_metadata_fields)" == \ + '["Phased-Update-Percentage"]' +else + expect_succ pulp deb publication create \ + --repository "${ENTITIES_NAME}_repo" \ + --simple +fi PUBLICATION_HREF=$(echo "$OUTPUT" | jq -r .pulp_href)