From 0158b855bd09c589259cbb9d5b4ed6797268f144 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Tue, 16 Mar 2021 20:48:31 +0100 Subject: [PATCH] Move common remote options to generic [noissue] --- pulpcore/cli/ansible/context.py | 29 ++----------------- pulpcore/cli/ansible/remote.py | 44 ++++------------------------ pulpcore/cli/common/context.py | 22 ++++++++++++-- pulpcore/cli/common/generic.py | 43 +++++++++++++++++++++++++++ pulpcore/cli/container/context.py | 29 ++----------------- pulpcore/cli/container/remote.py | 48 +++++-------------------------- pulpcore/cli/file/context.py | 30 +------------------ pulpcore/cli/file/remote.py | 46 +++++------------------------ pulpcore/cli/python/context.py | 19 ++---------- pulpcore/cli/python/remote.py | 12 ++++---- pulpcore/cli/rpm/context.py | 34 +++------------------- pulpcore/cli/rpm/remote.py | 42 +++++---------------------- 12 files changed, 108 insertions(+), 290 deletions(-) diff --git a/pulpcore/cli/ansible/context.py b/pulpcore/cli/ansible/context.py index 992b1d934..bab404169 100644 --- a/pulpcore/cli/ansible/context.py +++ b/pulpcore/cli/ansible/context.py @@ -3,6 +3,7 @@ from pulpcore.cli.common.context import ( EntityDefinition, PulpEntityContext, + PulpRemoteContext, PulpRepositoryContext, PulpRepositoryVersionContext, ) @@ -10,14 +11,6 @@ _ = gettext.gettext # TODO Add Role and Collection Content contexts -remote_nullables = [ - "ca_cert", - "client_cert", - "client_key", - "password", - "proxy_url", - "username", -] class PulpAnsibleDistributionContext(PulpEntityContext): @@ -38,7 +31,7 @@ def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: return body -class PulpAnsibleRoleRemoteContext(PulpEntityContext): +class PulpAnsibleRoleRemoteContext(PulpRemoteContext): ENTITY = "role remote" HREF = "ansible_role_remote_href" LIST_ID = "remotes_ansible_role_list" @@ -47,15 +40,8 @@ class PulpAnsibleRoleRemoteContext(PulpEntityContext): UPDATE_ID = "remotes_ansible_role_partial_update" DELETE_ID = "remotes_ansible_role_delete" - def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: - body = super().preprocess_body(body) - for nullable in remote_nullables: - if body.get(nullable) == "": - body[nullable] = None - return body - -class PulpAnsibleCollectionRemoteContext(PulpEntityContext): +class PulpAnsibleCollectionRemoteContext(PulpRemoteContext): ENTITY = "collection remote" HREF = "ansible_collection_remote_href" LIST_ID = "remotes_ansible_collection_list" @@ -69,9 +55,6 @@ def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: body = super().preprocess_body(body) if "requirements" in body.keys(): body["requirements_file"] = body.pop("requirements") - for nullable in remote_nullables + self.collection_nullable: - if body.get(nullable) == "": - body[nullable] = None return body @@ -94,9 +77,3 @@ class PulpAnsibleRepositoryContext(PulpRepositoryContext): SYNC_ID = "repositories_ansible_ansible_sync" MODIFY_ID = "repositories_ansible_ansible_modify" VERSION_CONTEXT = PulpAnsibleRepositoryVersionContext - - def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: - body = super().preprocess_body(body) - if body.get("description") == "": - body["description"] = None - return body diff --git a/pulpcore/cli/ansible/remote.py b/pulpcore/cli/ansible/remote.py index 20c7a0f9b..f6f9573cd 100644 --- a/pulpcore/cli/ansible/remote.py +++ b/pulpcore/cli/ansible/remote.py @@ -10,6 +10,8 @@ ) from pulpcore.cli.common.context import PulpContext, pass_pulp_context from pulpcore.cli.common.generic import ( + common_remote_create_options, + common_remote_update_options, create_command, destroy_command, href_option, @@ -59,38 +61,7 @@ def remote(ctx: click.Context, pulp_ctx: PulpContext, remote_type: str) -> None: lookup_options = [href_option, name_option] remote_options = [ - click.option("--ca-cert", help=_("a PEM encoded CA certificate")), - click.option("--client-cert", help=_("a PEM encoded client certificate")), - click.option("--client-key", help=_("a PEM encode private key")), - click.option("--tls-validation", help=_("if True, TLS peer validation must be performed")), - click.option("--proxy-url", help=_("format: scheme//user:password@host:port")), - click.option("--username", help=_("used for authentication when syncing")), - click.option("--password"), - click.option( - "--download-concurrency", type=int, help=_("total number of simultaneous connections") - ), click.option("--policy", help=_("policy to use when downloading")), - click.option( - "--total-timeout", - type=float, - help=_("aiohttp.ClientTimeout.total for download connections"), - ), - click.option( - "--connect-timeout", - type=float, - help=_("aiohttp.ClientTimeout.connect for download connections"), - ), - click.option( - "--sock-connect-timeout", - type=float, - help=_("aiohttp.ClientTimeout.sock_connect for download connections"), - ), - click.option( - "--sock-read-timeout", - type=float, - help=_("aiohttp.ClientTimeout.sock_read for download connections"), - ), - click.option("--rate-limit", type=int, help=_("limit download rate in requests per second")), ] collection_options = [ click.option( @@ -116,17 +87,12 @@ def remote(ctx: click.Context, pulp_ctx: PulpContext, remote_type: str) -> None: ), ] ansible_remote_options = remote_options + collection_options -create_options = [ - click.option("--name", required=True), - click.option("--url", required=True), -] + ansible_remote_options -update_options = ( - lookup_options + [click.option("--url", help=_("new url"))] + ansible_remote_options -) +create_options = common_remote_create_options + remote_options + ansible_remote_options +update_options = common_remote_update_options + remote_options + ansible_remote_options remote.add_command(list_command(decorators=[label_select_option])) remote.add_command(show_command(decorators=lookup_options)) remote.add_command(destroy_command(decorators=lookup_options)) remote.add_command(create_command(decorators=create_options)) -remote.add_command(update_command(decorators=update_options)) +remote.add_command(update_command(decorators=lookup_options + update_options)) remote.add_command(label_command()) diff --git a/pulpcore/cli/common/context.py b/pulpcore/cli/common/context.py index 203609ad1..3a0cbc2d4 100644 --- a/pulpcore/cli/common/context.py +++ b/pulpcore/cli/common/context.py @@ -3,7 +3,7 @@ import json import sys import time -from typing import IO, Any, ClassVar, Dict, List, Optional, Tuple, Type, Union +from typing import IO, Any, ClassVar, Dict, List, Optional, Set, Tuple, Type, Union import click import yaml @@ -232,7 +232,9 @@ class PulpEntityContext: CREATE_ID: ClassVar[str] UPDATE_ID: ClassVar[str] DELETE_ID: ClassVar[str] + NULLABLES: ClassVar[Set[str]] = set() + # Hidden values for the lazy entity lookup _entity: Optional[EntityDefinition] _entity_lookup: EntityDefinition @@ -317,9 +319,16 @@ def __init__( else: self.pulp_href = pulp_href + def _preprocess_value(self, key: str, value: Any) -> Any: + if key in self.NULLABLES and value == "": + return None + if isinstance(value, PulpEntityContext): + return value.pulp_href + return value + def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: return { - key: value.pulp_href if isinstance(value, PulpEntityContext) else value + key: self._preprocess_value(key, value) for key, value in body.items() if value is not None } @@ -459,6 +468,14 @@ class PulpRemoteContext(PulpEntityContext): ENTITY = "remote" ENTITIES = "remotes" + NULLABLES = { + "ca_cert", + "client_cert", + "client_key", + "password", + "proxy_url", + "username", + } def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: body = super().preprocess_body(body) @@ -525,6 +542,7 @@ class PulpRepositoryContext(PulpEntityContext): SYNC_ID: ClassVar[str] MODIFY_ID: ClassVar[str] VERSION_CONTEXT: ClassVar[Type[PulpRepositoryVersionContext]] + NULLABLES = {"description"} def get_version_context(self) -> PulpRepositoryVersionContext: return self.VERSION_CONTEXT(self.pulp_ctx, self) diff --git a/pulpcore/cli/common/generic.py b/pulpcore/cli/common/generic.py index 0b931b4cf..572a41cc0 100644 --- a/pulpcore/cli/common/generic.py +++ b/pulpcore/cli/common/generic.py @@ -209,6 +209,49 @@ def load_json_callback( cls=PulpOption, ) +common_remote_create_options = [ + click.option("--name", required=True), + click.option("--url", required=True), + click.option("--ca-cert", help=_("a PEM encoded CA certificate")), + click.option("--client-cert", help=_("a PEM encoded client certificate")), + click.option("--client-key", help=_("a PEM encode private key")), + click.option("--connect-timeout", type=float), + click.option( + "--download-concurrency", type=int, help=_("total number of simultaneous connections") + ), + click.option("--password"), + click.option("--proxy-url"), + click.option("--proxy-username"), + click.option("--proxy-password"), + click.option("--rate-limit", type=int, help=_("limit download rate in requests per second")), + click.option("--sock-connect-timeout", type=float), + click.option("--sock-read-timeout", type=float), + click.option("--tls-validation", type=bool), + click.option("--total-timeout", type=float), + click.option("--username"), +] + +common_remote_update_options = [ + click.option("--url"), + click.option("--ca-cert", help=_("a PEM encoded CA certificate")), + click.option("--client-cert", help=_("a PEM encoded client certificate")), + click.option("--client-key", help=_("a PEM encode private key")), + click.option("--connect-timeout", type=float), + click.option( + "--download-concurrency", type=int, help=_("total number of simultaneous connections") + ), + click.option("--password"), + click.option("--proxy-url"), + click.option("--proxy-username"), + click.option("--proxy-password"), + click.option("--rate-limit", type=int, help=_("limit download rate in requests per second")), + click.option("--sock-connect-timeout", type=float), + click.option("--sock-read-timeout", type=float), + click.option("--tls-validation", type=bool), + click.option("--total-timeout", type=float), + click.option("--username"), +] + ############################################################################## # Generic reusable commands diff --git a/pulpcore/cli/container/context.py b/pulpcore/cli/container/context.py index fc18cf709..3eaa44914 100644 --- a/pulpcore/cli/container/context.py +++ b/pulpcore/cli/container/context.py @@ -7,6 +7,7 @@ from pulpcore.cli.common.context import ( EntityDefinition, PulpEntityContext, + PulpRemoteContext, PulpRepositoryContext, PulpRepositoryVersionContext, ) @@ -55,7 +56,7 @@ def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: return body -class PulpContainerRemoteContext(PulpEntityContext): +class PulpContainerRemoteContext(PulpRemoteContext): ENTITY = "container remote" ENTITIES = "container remotes" HREF = "container_container_remote_href" @@ -64,20 +65,6 @@ class PulpContainerRemoteContext(PulpEntityContext): UPDATE_ID = "remotes_container_container_partial_update" DELETE_ID = "remotes_container_container_delete" - def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: - body = super().preprocess_body(body) - for nullable in [ - "ca_cert", - "client_cert", - "client_key", - "password", - "proxy_url", - "username", - ]: - if body.get(nullable) == "": - body[nullable] = None - return body - class PulpContainerRepositoryVersionContext(PulpRepositoryVersionContext): HREF = "container_container_repository_version_href" @@ -105,12 +92,6 @@ class PulpContainerRepositoryContext(PulpRepositoryContext): SYNC_ID = "repositories_container_container_sync" VERSION_CONTEXT = PulpContainerRepositoryVersionContext - def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: - body = super().preprocess_body(body) - if body.get("description") == "": - body["description"] = None - return body - class PulpContainerPushRepositoryContext(PulpRepositoryContext): HREF = "container_container_push_repository_href" @@ -123,9 +104,3 @@ class PulpContainerPushRepositoryContext(PulpRepositoryContext): # TODO Incorporate into capabilities # SYNC_ID = "repositories_container_container_push_sync" VERSION_CONTEXT = PulpContainerPushRepositoryVersionContext - - def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: - body = super().preprocess_body(body) - if body.get("description") == "": - body["description"] = None - return body diff --git a/pulpcore/cli/container/remote.py b/pulpcore/cli/container/remote.py index d8780f699..be1fd04fd 100644 --- a/pulpcore/cli/container/remote.py +++ b/pulpcore/cli/container/remote.py @@ -4,6 +4,8 @@ from pulpcore.cli.common.context import PulpContext, pass_pulp_context from pulpcore.cli.common.generic import ( + common_remote_create_options, + common_remote_update_options, create_command, destroy_command, href_option, @@ -37,51 +39,15 @@ def remote(ctx: click.Context, pulp_ctx: PulpContext, remote_type: str) -> None: lookup_options = [href_option, name_option] -create_options = [ - click.option("--name", required=True), - click.option("--url", required=True), - click.option("--ca-cert"), - click.option("--client-cert"), - click.option("--client-key"), - click.option("--connect-timeout", type=float), - click.option("--download-concurrency", type=int), - click.option("--password"), - click.option( - "--policy", type=click.Choice(["immediate", "on_demand", "streamed"], case_sensitive=False) - ), - click.option("--proxy-url"), - click.option("--sock-connect-timeout", type=float), - click.option("--sock-read-timeout", type=float), - click.option("--tls-validation", type=bool), - click.option("--total-timeout", type=float), - click.option("--username"), - # Container specific +remote_options = [ click.option("--upstream-name", required=True), ] -update_options = [ - click.option("--url"), - click.option("--ca-cert"), - click.option("--client-cert"), - click.option("--client-key"), - click.option("--connect-timeout", type=float), - click.option("--download-concurrency", type=int), - click.option("--password"), - click.option( - "--policy", type=click.Choice(["immediate", "on_demand", "streamed"], case_sensitive=False) - ), - click.option("--proxy-url"), - click.option("--sock-connect-timeout", type=float), - click.option("--sock-read-timeout", type=float), - click.option("--tls-validation", type=bool), - click.option("--total-timeout", type=float), - click.option("--username"), - # Container specific - click.option("--upstream-name"), -] remote.add_command(list_command(decorators=[label_select_option])) remote.add_command(show_command(decorators=lookup_options)) -remote.add_command(create_command(decorators=create_options)) -remote.add_command(update_command(decorators=lookup_options + update_options)) +remote.add_command(create_command(decorators=common_remote_create_options + remote_options)) +remote.add_command( + update_command(decorators=lookup_options + common_remote_update_options + remote_options) +) remote.add_command(destroy_command(decorators=lookup_options)) remote.add_command(label_command()) diff --git a/pulpcore/cli/file/context.py b/pulpcore/cli/file/context.py index 81cfc92e6..70fee2fdc 100644 --- a/pulpcore/cli/file/context.py +++ b/pulpcore/cli/file/context.py @@ -29,15 +29,7 @@ class PulpFileDistributionContext(PulpEntityContext): CREATE_ID = "distributions_file_file_create" UPDATE_ID = "distributions_file_file_partial_update" DELETE_ID = "distributions_file_file_delete" - - def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: - body = super().preprocess_body(body) - for nullable in [ - "publication", - ]: - if body.get(nullable) == "": - body[nullable] = None - return body + NULLABLES = {"publication"} class PulpFilePublicationContext(PulpEntityContext): @@ -68,20 +60,6 @@ class PulpFileRemoteContext(PulpRemoteContext): UPDATE_ID = "remotes_file_file_partial_update" DELETE_ID = "remotes_file_file_delete" - def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: - body = super().preprocess_body(body) - for nullable in [ - "ca_cert", - "client_cert", - "client_key", - "password", - "proxy_url", - "username", - ]: - if body.get(nullable) == "": - body[nullable] = None - return body - class PulpFileRepositoryVersionContext(PulpRepositoryVersionContext): HREF = "file_file_repository_version_href" @@ -102,9 +80,3 @@ class PulpFileRepositoryContext(PulpRepositoryContext): SYNC_ID = "repositories_file_file_sync" MODIFY_ID = "repositories_file_file_modify" VERSION_CONTEXT = PulpFileRepositoryVersionContext - - def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: - body = super().preprocess_body(body) - if body.get("description") == "": - body["description"] = None - return body diff --git a/pulpcore/cli/file/remote.py b/pulpcore/cli/file/remote.py index 6e5182164..2bbd3efab 100644 --- a/pulpcore/cli/file/remote.py +++ b/pulpcore/cli/file/remote.py @@ -4,6 +4,8 @@ from pulpcore.cli.common.context import PulpContext, pass_pulp_context from pulpcore.cli.common.generic import ( + common_remote_create_options, + common_remote_update_options, create_command, destroy_command, href_option, @@ -37,51 +39,17 @@ def remote(ctx: click.Context, pulp_ctx: PulpContext, remote_type: str) -> None: lookup_options = [href_option, name_option] -create_options = [ - click.option("--name", required=True), - click.option("--url", required=True), - click.option("--ca-cert"), - click.option("--client-cert"), - click.option("--client-key"), - click.option("--connect-timeout", type=float), - click.option("--download-concurrency", type=int), - click.option("--password"), +file_remote_options = [ click.option( "--policy", type=click.Choice(["immediate", "on_demand", "streamed"], case_sensitive=False) ), - click.option("--proxy-url"), - click.option("--proxy-username"), - click.option("--proxy-password"), - click.option("--sock-connect-timeout", type=float), - click.option("--sock-read-timeout", type=float), - click.option("--tls-validation", type=bool), - click.option("--total-timeout", type=float), - click.option("--username"), -] -update_options = [ - click.option("--url"), - click.option("--ca-cert"), - click.option("--client-cert"), - click.option("--client-key"), - click.option("--connect-timeout", type=float), - click.option("--download-concurrency", type=int), - click.option("--password"), - click.option( - "--policy", type=click.Choice(["immediate", "on_demand", "streamed"], case_sensitive=False) - ), - click.option("--proxy-url"), - click.option("--proxy-username"), - click.option("--proxy-password"), - click.option("--sock-connect-timeout", type=float), - click.option("--sock-read-timeout", type=float), - click.option("--tls-validation", type=bool), - click.option("--total-timeout", type=float), - click.option("--username"), ] remote.add_command(list_command(decorators=[label_select_option])) remote.add_command(show_command(decorators=lookup_options)) -remote.add_command(create_command(decorators=create_options)) -remote.add_command(update_command(decorators=lookup_options + update_options)) +remote.add_command(create_command(decorators=common_remote_create_options + file_remote_options)) +remote.add_command( + update_command(decorators=lookup_options + common_remote_update_options + file_remote_options) +) remote.add_command(destroy_command(decorators=lookup_options)) remote.add_command(label_command()) diff --git a/pulpcore/cli/python/context.py b/pulpcore/cli/python/context.py index 69f3f8bbc..cc4c2b4c9 100644 --- a/pulpcore/cli/python/context.py +++ b/pulpcore/cli/python/context.py @@ -3,6 +3,7 @@ from pulpcore.cli.common.context import ( EntityDefinition, PulpEntityContext, + PulpRemoteContext, PulpRepositoryContext, PulpRepositoryVersionContext, ) @@ -26,15 +27,7 @@ class PulpPythonDistributionContext(PulpEntityContext): CREATE_ID = "distributions_python_pypi_create" UPDATE_ID = "distributions_python_pypi_partial_update" DELETE_ID = "distributions_python_pypi_delete" - - def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: - body = super().preprocess_body(body) - for nullable in [ - "publication", - ]: - if body.get(nullable) == "": - body[nullable] = None - return body + NULLABLES = {"publication"} class PulpPythonPublicationContext(PulpEntityContext): @@ -55,7 +48,7 @@ def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: return body -class PulpPythonRemoteContext(PulpEntityContext): +class PulpPythonRemoteContext(PulpRemoteContext): ENTITY = "python remote" ENTITIES = "python remotes" HREF = "python_python_remote_href" @@ -85,9 +78,3 @@ class PulpPythonRepositoryContext(PulpRepositoryContext): SYNC_ID = "repositories_python_python_sync" MODIFY_ID = "repositories_python_python_modify" VERSION_CONTEXT = PulpPythonRepositoryVersionContext - - def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: - body = super().preprocess_body(body) - if body.get("description") == "": - body["description"] = None - return body diff --git a/pulpcore/cli/python/remote.py b/pulpcore/cli/python/remote.py index c7aabfa3e..b30855360 100644 --- a/pulpcore/cli/python/remote.py +++ b/pulpcore/cli/python/remote.py @@ -4,6 +4,8 @@ from pulpcore.cli.common.context import PulpContext, pass_pulp_context from pulpcore.cli.common.generic import ( + common_remote_create_options, + common_remote_update_options, create_command, destroy_command, href_option, @@ -38,11 +40,7 @@ def remote(ctx: click.Context, pulp_ctx: PulpContext, remote_type: str) -> None: lookup_options = [href_option, name_option] -create_options = [ - click.option("--name", required=True), -] python_remote_options = [ - click.option("--url"), click.option("--includes", callback=load_json_callback, help=_("Package allowlist")), click.option("--excludes", callback=load_json_callback, help=_("Package blocklist")), click.option("--prereleases", type=click.BOOL, default=True), @@ -50,8 +48,10 @@ def remote(ctx: click.Context, pulp_ctx: PulpContext, remote_type: str) -> None: remote.add_command(list_command(decorators=[label_select_option])) remote.add_command(show_command(decorators=lookup_options)) remote.add_command(destroy_command(decorators=lookup_options)) -remote.add_command(create_command(decorators=create_options + python_remote_options)) -remote.add_command(update_command(decorators=lookup_options + python_remote_options)) +remote.add_command(create_command(decorators=common_remote_create_options + python_remote_options)) +remote.add_command( + update_command(decorators=lookup_options + common_remote_update_options + python_remote_options) +) remote.add_command(label_command()) # TODO Add support for 'from_bandersnatch' remote create endpoint diff --git a/pulpcore/cli/rpm/context.py b/pulpcore/cli/rpm/context.py index a3cf6eafe..9e38d90fd 100644 --- a/pulpcore/cli/rpm/context.py +++ b/pulpcore/cli/rpm/context.py @@ -3,6 +3,7 @@ from pulpcore.cli.common.context import ( EntityDefinition, PulpEntityContext, + PulpRemoteContext, PulpRepositoryContext, PulpRepositoryVersionContext, ) @@ -18,15 +19,7 @@ class PulpRpmDistributionContext(PulpEntityContext): CREATE_ID = "distributions_rpm_rpm_create" UPDATE_ID = "distributions_rpm_rpm_partial_update" DELETE_ID = "distributions_rpm_rpm_delete" - - def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: - body = super().preprocess_body(body) - for nullable in [ - "publication", - ]: - if body.get(nullable) == "": - body[nullable] = None - return body + NULLABLES = {"publication"} class PulpRpmPublicationContext(PulpEntityContext): @@ -46,7 +39,7 @@ def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: return body -class PulpRpmRemoteContext(PulpEntityContext): +class PulpRpmRemoteContext(PulpRemoteContext): ENTITY = "remote" HREF = "rpm_rpm_remote_href" LIST_ID = "remotes_rpm_rpm_list" @@ -55,20 +48,6 @@ class PulpRpmRemoteContext(PulpEntityContext): UPDATE_ID = "remotes_rpm_rpm_partial_update" DELETE_ID = "remotes_rpm_rpm_delete" - def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: - body = super().preprocess_body(body) - for nullable in [ - "ca_cert", - "client_cert", - "client_key", - "password", - "proxy_url", - "username", - ]: - if body.get(nullable) == "": - body[nullable] = None - return body - class PulpRpmRepositoryVersionContext(PulpRepositoryVersionContext): HREF = "rpm_rpm_repository_version_href" @@ -88,9 +67,4 @@ class PulpRpmRepositoryContext(PulpRepositoryContext): DELETE_ID = "repositories_rpm_rpm_delete" SYNC_ID = "repositories_rpm_rpm_sync" VERSION_CONTEXT = PulpRpmRepositoryVersionContext - - def preprocess_body(self, body: EntityDefinition) -> EntityDefinition: - body = super().preprocess_body(body) - if body.get("description") == "": - body["description"] = None - return body + NULLABLES = {"description"} diff --git a/pulpcore/cli/rpm/remote.py b/pulpcore/cli/rpm/remote.py index 5439ee856..de969ea32 100644 --- a/pulpcore/cli/rpm/remote.py +++ b/pulpcore/cli/rpm/remote.py @@ -4,6 +4,8 @@ from pulpcore.cli.common.context import PulpContext, pass_pulp_context from pulpcore.cli.common.generic import ( + common_remote_create_options, + common_remote_update_options, create_command, destroy_command, href_option, @@ -37,47 +39,17 @@ def remote(ctx: click.Context, pulp_ctx: PulpContext, remote_type: str) -> None: lookup_options = [href_option, name_option] -create_options = [ - click.option("--name", required=True), - click.option("--url", required=True), - click.option("--ca-cert"), - click.option("--client-cert"), - click.option("--client-key"), - click.option("--connect-timeout", type=float), - click.option("--download-concurrency", type=int), - click.option("--password"), +rpm_remote_options = [ click.option( "--policy", type=click.Choice(["immediate", "on_demand", "streamed"], case_sensitive=False) ), - click.option("--proxy-url"), - click.option("--sock-connect-timeout", type=float), - click.option("--sock-read-timeout", type=float), - click.option("--tls-validation", type=bool), - click.option("--total-timeout", type=float), - click.option("--username"), -] -update_options = [ - click.option("--url"), - click.option("--ca-cert"), - click.option("--client-cert"), - click.option("--client-key"), - click.option("--connect-timeout", type=float), - click.option("--download-concurrency", type=int), - click.option("--password"), - click.option( - "--policy", type=click.Choice(["immediate", "on_demand", "streamed"], case_sensitive=False) - ), - click.option("--proxy-url"), - click.option("--sock-connect-timeout", type=float), - click.option("--sock-read-timeout", type=float), - click.option("--tls-validation", type=bool), - click.option("--total-timeout", type=float), - click.option("--username"), ] remote.add_command(list_command(decorators=[label_select_option])) remote.add_command(show_command(decorators=lookup_options)) -remote.add_command(create_command(decorators=create_options)) -remote.add_command(update_command(decorators=lookup_options + update_options)) +remote.add_command(create_command(decorators=common_remote_create_options + rpm_remote_options)) +remote.add_command( + update_command(decorators=lookup_options + common_remote_update_options + rpm_remote_options) +) remote.add_command(destroy_command(decorators=lookup_options)) remote.add_command(label_command())