From ace04b46f1770fc0c089fad744fbf6fd64831cb5 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Mar 01 2021 12:24:51 +0000 Subject: [PATCH 1/2] hub: sidetag suffixes Fixes: https://pagure.io/koji/issue/2729 --- diff --git a/plugins/hub/sidetag.conf b/plugins/hub/sidetag.conf index 743f848..260789d 100644 --- a/plugins/hub/sidetag.conf +++ b/plugins/hub/sidetag.conf @@ -1,3 +1,5 @@ [sidetag] # automatically remove sidetag on untagging last package remove_empty = off +# potential suffixes for sidetag names +allowed_suffixes = stack-gate diff --git a/plugins/hub/sidetag_hub.py b/plugins/hub/sidetag_hub.py index 6bcfee1..4dc8247 100644 --- a/plugins/hub/sidetag_hub.py +++ b/plugins/hub/sidetag_hub.py @@ -26,6 +26,7 @@ from kojihub import ( # noqa: E402 CONFIG_FILE = "/etc/koji-hub/plugins/sidetag.conf" CONFIG = None +ALLOWED_SUFFIXES = [] def is_sidetag(taginfo, raise_error=False): @@ -70,7 +71,7 @@ class SidetagOwnerTest(koji.policy.MatchTest): # API calls @export -def createSideTag(basetag, debuginfo=False): +def createSideTag(basetag, debuginfo=False, suffix=None): """Create a side tag. :param basetag: name or ID of base tag @@ -78,8 +79,17 @@ def createSideTag(basetag, debuginfo=False): :param debuginfo: should buildroot repos contain debuginfo? :type debuginfo: bool + + :param suffix: suffix which will be appended to generated sidetag name + List of allowed suffixes needs to be defined in config. + :type suffix: str + + :returns dict: sidetag name + id """ + if suffix and suffix not in ALLOWED_SUFFIXES: + raise koji.GenericError("%s suffix is not allowed for sidetag" % suffix) + # Any logged-in user is able to request creation of side tags, # as long the request meets the policy. context.session.assertLogin() @@ -109,6 +119,8 @@ def createSideTag(basetag, debuginfo=False): # id assigned by _create_tag tag_id = nextval("tag_id_seq") + 1 sidetag_name = "%s-side-%s" % (basetag["name"], tag_id) + if suffix: + sidetag_name += '-%s' % suffix extra = { "sidetag": True, "sidetag_user": user["name"], @@ -306,3 +318,5 @@ if not CONFIG: "sidetag", "remove_empty" ): handle_sidetag_untag = callback("postUntag")(handle_sidetag_untag) + if CONFIG.has_option("sidetag", "allowed_suffixes"): + ALLOWED_SUFFIXES = CONFIG.get("sidetag", "allowed_suffixes").split(',') From 031180aaeec5ae2ae88d87e4fa8bb2866feb3f21 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Mar 01 2021 12:34:43 +0000 Subject: [PATCH 2/2] cli: sidetag --suffix option --- diff --git a/plugins/cli/sidetag_cli.py b/plugins/cli/sidetag_cli.py index 4b9cc34..8713bde 100644 --- a/plugins/cli/sidetag_cli.py +++ b/plugins/cli/sidetag_cli.py @@ -33,15 +33,26 @@ def handle_add_sidetag(options, session, args): parser.add_argument( "--debuginfo", action="store_true", help=_("Buildroot repo will contain debuginfos") ) + parser.add_argument( + "--suffix", actions="store", help=_("Suffix from hub-supported ones") + ) opts = parser.parse_args(args) activate_session(session, options) + kwargs = {"debuginfo": opts.debuginfo} + if opts.suffix: + kwargs['suffix'] = opts.suffix try: - tag = session.createSideTag(opts.basetag, debuginfo=opts.debuginfo) + tag = session.createSideTag(opts.basetag, **kwargs) except koji.ActionNotAllowed: parser.error(_("Policy violation")) + except koji.ParameterError as ex: + if 'suffix' in str(ex): + parser.error(_("Hub is older and doesn't support --suffix, please run it without it")) + else: + raise if not opts.quiet: print(tag["name"]) diff --git a/plugins/hub/sidetag.conf b/plugins/hub/sidetag.conf index 260789d..fefa32d 100644 --- a/plugins/hub/sidetag.conf +++ b/plugins/hub/sidetag.conf @@ -2,4 +2,4 @@ # automatically remove sidetag on untagging last package remove_empty = off # potential suffixes for sidetag names -allowed_suffixes = stack-gate +# allowed_suffixes =