From b457db131f4ef68ab550d8c4ec7507dbb3be29ef Mon Sep 17 00:00:00 2001 From: Ales Raszka Date: Jul 11 2016 12:59:34 +0000 Subject: Enable to remove signed rpm --- diff --git a/cli/koji b/cli/koji index 0abe244..185da06 100755 --- a/cli/koji +++ b/cli/koji @@ -1833,6 +1833,38 @@ def handle_write_signed_rpm(options, session, args): for rpm in rpms: session.writeSignedRPM(rpm['id'], key) +def handle_remove_signed_rpm(options, session, args): + "[admin] Remove signed rpms" + usage = _("usage: %prog remove-signed-rpm [options] n-v-r [n-v-r...]") + usage += _("\n(Specify the --help global option for a list of other help options)") + parser = OptionParser(usage=usage) + parser.add_option("--buildid", help=_("Specify a build rather than an n-v-r")) + (options, args) = parser.parse_args(args) + if len(args) < 1: + parser.error(_("A signature key must be specified")) + assert False + if len(args) < 2 and not options.buildid: + parser.error(_("At least one RPM must be specified")) + assert False + key = args.pop(0) + activate_session(session) + count = 1 + if options.buildid: + rpms = session.listRPMs(int(options.buildid)) + for rpm in rpms: + print rpm + print "%d/%d - RPM id: %d" % (count, len(rpms), rpm['id']) + session.removeSignedRPM(rpm['id'], key) + count += 1 + else: + for nvr in args: + build = session.getBuild(nvr) + rpms = session.listRPMs(build['id']) + for rpm in rpms: + print "%d/%d - RPM id: %d" % (count, len(rpms), rpm['id']) + session.removeSignedRPM(rpm['id'], key) + count += 1 + def handle_prune_signed_copies(options, session, args): "[admin] Prune signed copies" usage = _("usage: %prog prune-sigs [options]") diff --git a/hub/kojihub.py b/hub/kojihub.py index 2ea1689..4e0cbda 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -5974,6 +5974,26 @@ def write_signed_rpm(an_rpm, sigkey, force=False): koji.ensuredir(os.path.dirname(signedpath)) koji.splice_rpm_sighdr(sighdr, rpm_path, signedpath) +def remove_signed_rpm(rpm_id, sigkey): + """ Remove signed copy of rpm and sigkey from database""" + rpm_info = get_rpm(rpm_id, strict=True) + if rpm_info['external_repo_id']: + raise koji.GenericError, "Not an internal rpm: %s (from %s)" \ + % (rpm_id, rpm_info['external_repo_name']) + build_info = get_build(rpm_info['build_id']) + builddir = koji.pathinfo.build(build_info) + + rpm_id = rpm_info['id'] + delete_query = """DELETE FROM rpmsigs WHERE rpm_id=%(rpm_id)i AND sigkey=%(sigkey)s""" + _dml(delete_query, locals()) + + signedpath = "%s/%s" % (builddir, koji.pathinfo.signed(rpm_info, sigkey)) + if os.path.exists(signedpath): + os.unlink(signedpath) + + sigpath = "%s/%s" % (builddir, koji.pathinfo.sighdr(rpm_info, sigkey)) + if os.path.exists(sigpath): + os.unlink(sigpath) def query_history(tables=None, **kwargs): """Returns history data from various tables that support it @@ -9400,6 +9420,8 @@ class RootExports(object): context.session.assertPerm('sign') return add_rpm_sig(an_rpm, base64.decodestring(data)) + removeSignedRPM = staticmethod(remove_signed_rpm) + findBuildID = staticmethod(find_build_id) getTagID = staticmethod(get_tag_id) getTag = staticmethod(get_tag) diff --git a/tests/test_cli/data/list-commands-admin.txt b/tests/test_cli/data/list-commands-admin.txt index f6f7db2..6bd4f3c 100644 --- a/tests/test_cli/data/list-commands-admin.txt +++ b/tests/test_cli/data/list-commands-admin.txt @@ -44,6 +44,7 @@ admin commands: remove-external-repo Remove an external repo from a tag or tags, or remove entirely remove-host-from-channel Remove a host from a channel remove-pkg Remove a package from the listing for tag + remove-signed-rpm Remove signed rpms remove-tag Remove a tag remove-tag-inheritance Remove a tag inheritance link remove-target Remove a build target diff --git a/tests/test_cli/data/list-commands.txt b/tests/test_cli/data/list-commands.txt index d2b991f..272b630 100644 --- a/tests/test_cli/data/list-commands.txt +++ b/tests/test_cli/data/list-commands.txt @@ -44,6 +44,7 @@ admin commands: remove-external-repo Remove an external repo from a tag or tags, or remove entirely remove-host-from-channel Remove a host from a channel remove-pkg Remove a package from the listing for tag + remove-signed-rpm Remove signed rpms remove-tag Remove a tag remove-tag-inheritance Remove a tag inheritance link remove-target Remove a build target