From 895665cbb9924adfd8569df2ea8732f1f92dff28 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Mon, 21 Jul 2025 17:01:14 -0400 Subject: [PATCH 1/3] enable new signature features in cli --- cli/koji_cli/commands.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 2e15b96e..bcacdf0e 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -1364,6 +1364,7 @@ def handle_import(goptions, session, args): parser.add_option("--test", action="store_true", help="Don't actually import") parser.add_option("--create-build", action="store_true", help="Auto-create builds as needed") parser.add_option("--src-epoch", help="When auto-creating builds, use this epoch") + parser.add_option("--sigkey", help="Override the sigkey value") (options, args) = parser.parse_args(args) if len(args) < 1: parser.error("At least one package must be specified") @@ -1430,8 +1431,11 @@ def handle_import(goptions, session, args): sys.stdout.flush() sys.stdout.write("importing %s... " % path) sys.stdout.flush() + kwargs = {} + if options.sigkey: + kwargs['sigkey'] = options.sigkey try: - session.importRPM(serverdir, os.path.basename(path)) + session.importRPM(serverdir, os.path.basename(path), **kwargs) except koji.GenericError as e: print("\nError importing: %s" % str(e).splitlines()[-1]) sys.stdout.flush() @@ -1714,6 +1718,7 @@ def handle_import_sig(goptions, session, args): help="Also import unsigned sig headers") parser.add_option("--write", action="store_true", help=SUPPRESS_HELP) parser.add_option("--test", action="store_true", help="Test mode -- don't actually import") + parser.add_option("--sigkey", action="store", default=None, help="Specify signature key") (options, args) = parser.parse_args(args) if len(args) < 1: parser.error("At least one package must be specified") @@ -1766,14 +1771,39 @@ def handle_import_sig(goptions, session, args): warn(" The system already has a signature for this rpm with key %s" % sigkey) warn(" The two signature headers are not the same") continue + kwargs = {} + if options.sigkey: + kwargs['sigkey'] = options.sigkey print("Importing signature [key %s] from %s..." % (sigkey, path)) if not options.test: - session.addRPMSig(rinfo['id'], base64encode(sighdr)) + session.addRPMSig(rinfo['id'], base64encode(sighdr), **kwargs) print("Writing signed copy") if not options.test: session.writeSignedRPM(rinfo['id'], sigkey) +def handle_rename_sig(goptions, session, args): + "[admin] Adjust the sigkey value for an rpm signature" + usage = "usage: %prog rename-sig [options] " + parser = OptionParser(usage=get_usage_str(usage)) + (options, args) = parser.parse_args(args) + if len(args) != 3: + parser.error("This command takes exactly three arguments") + + rpminfo = args[0] + oldkey = args[1] + newkey = args[2] + + activate_session(session, goptions) + + try: + session.renameRPMSig(rpminfo, oldkey, newkey) + except koji.GenericError as e: + # the api error messages are sufficiently descriptive + msg = str(e) + error(msg) + + def handle_remove_sig(goptions, session, args): "[admin] Remove signed RPMs from db and disk" usage = "usage: %prog remove-sig [options] " From b592d0eee1e1d0364aeba4de181b4960e40e5b1e Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Mon, 21 Jul 2025 17:19:46 -0400 Subject: [PATCH 2/3] adjust unit tests --- tests/test_cli/data/list-commands-admin.txt | 1 + tests/test_cli/data/list-commands.txt | 1 + tests/test_cli/test_import.py | 1 + tests/test_cli/test_import_sig.py | 1 + 4 files changed, 4 insertions(+) diff --git a/tests/test_cli/data/list-commands-admin.txt b/tests/test_cli/data/list-commands-admin.txt index 84f31803..24692ee8 100644 --- a/tests/test_cli/data/list-commands-admin.txt +++ b/tests/test_cli/data/list-commands-admin.txt @@ -57,6 +57,7 @@ admin commands: remove-tag Remove a tag remove-tag-inheritance Remove a tag inheritance link remove-target Remove a build target + rename-sig Adjust the sigkey value for an rpm signature reserve-cg Reserve a build entry for later import restart-hosts Restart enabled hosts revoke-cg-access Remove a user from a content generator diff --git a/tests/test_cli/data/list-commands.txt b/tests/test_cli/data/list-commands.txt index 9671bba6..723940b3 100644 --- a/tests/test_cli/data/list-commands.txt +++ b/tests/test_cli/data/list-commands.txt @@ -57,6 +57,7 @@ admin commands: remove-tag Remove a tag remove-tag-inheritance Remove a tag inheritance link remove-target Remove a build target + rename-sig Adjust the sigkey value for an rpm signature reserve-cg Reserve a build entry for later import restart-hosts Restart enabled hosts revoke-cg-access Remove a user from a content generator diff --git a/tests/test_cli/test_import.py b/tests/test_cli/test_import.py index 7a916c46..4807994a 100644 --- a/tests/test_cli/test_import.py +++ b/tests/test_cli/test_import.py @@ -697,6 +697,7 @@ Options: --create-build Auto-create builds as needed --src-epoch=SRC_EPOCH When auto-creating builds, use this epoch + --sigkey=SIGKEY Override the sigkey value """ % self.progname) diff --git a/tests/test_cli/test_import_sig.py b/tests/test_cli/test_import_sig.py index 00bdb4af..c95d43d8 100644 --- a/tests/test_cli/test_import_sig.py +++ b/tests/test_cli/test_import_sig.py @@ -315,6 +315,7 @@ Options: -h, --help show this help message and exit --with-unsigned Also import unsigned sig headers --test Test mode -- don't actually import + --sigkey=SIGKEY Specify signature key """ % self.progname) From 4547e7ed0a73aad02e7f29358caff173813d8f7f Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Thu, 31 Jul 2025 10:39:23 -0400 Subject: [PATCH 3/3] simplify error handler --- cli/koji_cli/commands.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index bcacdf0e..7eaf77fb 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -1800,8 +1800,7 @@ def handle_rename_sig(goptions, session, args): session.renameRPMSig(rpminfo, oldkey, newkey) except koji.GenericError as e: # the api error messages are sufficiently descriptive - msg = str(e) - error(msg) + error(str(e)) def handle_remove_sig(goptions, session, args):