From ba7ec1fe6d3d60c8c446342088cf0b650dad75ca Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Aug 03 2023 11:02:44 +0000 Subject: [PATCH 1/2] sidetag: extend is_sidetag_owner for untag ops Related: https://pagure.io/koji/issue/3848 --- diff --git a/docs/source/plugins.rst b/docs/source/plugins.rst index 5a0f92f..be760f1 100644 --- a/docs/source/plugins.rst +++ b/docs/source/plugins.rst @@ -122,8 +122,12 @@ Example for `/etc/koji-hub/hub.conf`: match action block && is_sidetag_owner :: allow all :: deny -There are two special policy tests `is_sidetag` and `is_sidetag_owner` with -expectable behaviour. +There are two special policy tests ``is_sidetag`` and ``is_sidetag_owner`` with +expectable behaviour. ``is_sidetag_owner`` can handle optional +``tag``/``fromtag``/``both`` keywords which specify data to be tested. Default +is testing ``tag`` in policy data, ``fromtag`` can test this field (e.g. in +``untagBuild`` case) and ``both`` fails if any of the involved tags is not owned +by sidetag owner. Now Sidetag Koji plugin should be installed. To verify that, run `koji list-api` command -- it should now display `createSideTag` diff --git a/plugins/hub/sidetag_hub.py b/plugins/hub/sidetag_hub.py index 6f3a730..bb910ed 100644 --- a/plugins/hub/sidetag_hub.py +++ b/plugins/hub/sidetag_hub.py @@ -65,9 +65,27 @@ class SidetagOwnerTest(koji.policy.MatchTest): name = 'is_sidetag_owner' def run(self, data): + values = self.str.split()[1:] + if len(values) > 1: + raise koji.GenericError("Just one argument is allowed for this test.") + elif values: + value = values[0] + if value not in ('tag', 'fromtag', 'both'): + raise koji.GenericError("Policy test is_sidetag_owner has only " + f"/tag/fromtag/both options (got {value})") + if value == 'both': + values = ['tag', 'fromtag'] + else: + values = ['tag'] + user = policy_get_user(data) - tag = get_tag(data['tag']) - return is_sidetag_owner(tag, user) + for value in values: + if value not in data: + return False + tag = get_tag(value) + if not tag or not is_sidetag_owner(tag, user): + return False + return True # API calls From cb921e2f8a013e0235e0d331a0503c25e56f71b6 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Aug 03 2023 11:02:44 +0000 Subject: [PATCH 2/2] better variable naming --- diff --git a/plugins/hub/sidetag_hub.py b/plugins/hub/sidetag_hub.py index bb910ed..3cd76ce 100644 --- a/plugins/hub/sidetag_hub.py +++ b/plugins/hub/sidetag_hub.py @@ -65,24 +65,24 @@ class SidetagOwnerTest(koji.policy.MatchTest): name = 'is_sidetag_owner' def run(self, data): - values = self.str.split()[1:] - if len(values) > 1: + fields = self.str.split()[1:] + if len(fields) > 1: raise koji.GenericError("Just one argument is allowed for this test.") - elif values: - value = values[0] - if value not in ('tag', 'fromtag', 'both'): + elif fields: + key = fields[0] + if key not in ('tag', 'fromtag', 'both'): raise koji.GenericError("Policy test is_sidetag_owner has only " - f"/tag/fromtag/both options (got {value})") - if value == 'both': - values = ['tag', 'fromtag'] + f"/tag/fromtag/both options (got {key})") + if key == 'both': + fields = ['tag', 'fromtag'] else: - values = ['tag'] + fields = ['tag'] user = policy_get_user(data) - for value in values: - if value not in data: + for field in fields: + if field not in data: return False - tag = get_tag(value) + tag = get_tag(data[field]) if not tag or not is_sidetag_owner(tag, user): return False return True