Skip to content
Open
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/+fix-add-signing-service.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed `add-signing-service` management command failing with "There are N keys matching the key id" for PGP keys that have subkeys.
15 changes: 11 additions & 4 deletions pulpcore/app/management/commands/add-signing-service.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,17 @@ def handle(self, *args, **options):
if result.returncode != 0:
raise CommandError(result.stderr.strip())

fpr_lines = [line for line in result.stdout.splitlines() if line.startswith("fpr:")]
if len(fpr_lines) != 1:
raise CommandError(_("There are {} keys matching the key id.").format(len(fpr_lines)))
fingerprint = fpr_lines[0].split(":")[9]
lines = result.stdout.splitlines()

# Count actual keys (pub:/sec: lines), not fingerprint lines. GPG emits
# a separate fpr: line for the primary key and each subkey, so a single
# key with subkeys produces multiple fpr: lines.
key_lines = [l for l in lines if l.startswith(("pub:", "sec:"))]
if len(key_lines) != 1:
raise CommandError(_("There are {} keys matching the key id.").format(len(key_lines)))

# Use the primary key fingerprint (first fpr: line in GPG's output).
fingerprint = [l.split(":")[9] for l in lines if l.startswith("fpr:")][0]

result = subprocess.run(
gpg_cmd + ["--armor", "--export", key_id],
Expand Down
Loading