From 07766a8730b73229c09089d7e144a38960552518 Mon Sep 17 00:00:00 2001 From: Aliaksei Klimau Date: Wed, 11 Mar 2026 13:52:27 +0100 Subject: [PATCH] Fix remove-signing-service handling, can now remove service without --class argument. (cherry picked from commit 848f3e063204dde9f9016abe8392b5eb8e072283) --- CHANGES/7318.bugfix | 1 + .../commands/remove-signing-service.py | 46 +++++++++++-------- 2 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 CHANGES/7318.bugfix diff --git a/CHANGES/7318.bugfix b/CHANGES/7318.bugfix new file mode 100644 index 00000000000..6b7722489fc --- /dev/null +++ b/CHANGES/7318.bugfix @@ -0,0 +1 @@ +Fix remove-signing-service handling, can now remove service without --class argument. diff --git a/pulpcore/app/management/commands/remove-signing-service.py b/pulpcore/app/management/commands/remove-signing-service.py index d005c4ff64b..1e420e7ba1c 100644 --- a/pulpcore/app/management/commands/remove-signing-service.py +++ b/pulpcore/app/management/commands/remove-signing-service.py @@ -24,41 +24,47 @@ def add_arguments(self, parser): ) parser.add_argument( "--class", - default="core:AsciiArmoredDetachedSigningService", + default=None, required=False, help=_("Signing service class prefixed by the app label separated by a colon."), ) def handle(self, *args, **options): name = options["name"] - if ":" not in options["class"]: - raise CommandError(_("The signing service class was not provided in a proper format.")) - app_label, service_class = options["class"].split(":") + if options["class"] is not None: + if ":" not in options["class"]: + raise CommandError( + _("The signing service class was not provided in a proper format.") + ) + app_label, service_class = options["class"].split(":") - try: - SigningService = apps.get_model(app_label, service_class) - except LookupError as e: - raise CommandError(str(e)) - if not issubclass(SigningService, BaseSigningService): - raise CommandError( - _("Class '{}' is not a subclass of the base 'core:SigningService' class.").format( - options["class"] + try: + signing_service_class = apps.get_model(app_label, service_class) + except LookupError as e: + raise CommandError(str(e)) + + if not issubclass(signing_service_class, BaseSigningService): + raise CommandError( + _( + "Class '{}' is not a subclass of the base 'core:SigningService' class." + ).format(options["class"]) ) - ) + # If --class is not provided, query the base SigningService + else: + signing_service_class = BaseSigningService try: - SigningService.objects.get(name=name).delete() + signing_service = signing_service_class.objects.get(name=name) + except ObjectDoesNotExist: + raise CommandError(_("Signing service '{}' does not exist.").format(name)) + + try: + signing_service.delete() except IntegrityError: raise CommandError( _("Signing service '{}' could not be removed because it's still in use.").format( name ) ) - except ObjectDoesNotExist: - raise CommandError( - _("Signing service '{}' of class '{}' does not exists.").format( - name, options["class"] - ) - ) else: self.stdout.write(_("Signing service '{}' has been successfully removed.").format(name))