Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/7318.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix remove-signing-service handling, can now remove service without --class argument.
46 changes: 26 additions & 20 deletions pulpcore/app/management/commands/remove-signing-service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Loading