diff options
author | James E. Blair <jeblair@redhat.com> | 2020-02-05 14:43:28 -0800 |
---|---|---|
committer | James E. Blair <jeblair@redhat.com> | 2020-02-06 15:59:59 -0800 |
commit | aea473fb7758ec2d104cb5ec5dab0eaa507b39b4 (patch) | |
tree | 1664fcfadc06349e8d1a6a9464249d0fb72a81c5 /zuul/web | |
parent | 61e5c3a0f90747b2b27216eb38e46e50f6a7d959 (diff) | |
download | zuul-aea473fb7758ec2d104cb5ec5dab0eaa507b39b4.tar.gz |
Extract allow/disallow filter into util function
This pattern is used in at least 2 places and may become more
prevalent as re2 is used.
Change-Id: Ibd6301cee54eacfbff2063cd5a9d3ea6df4635aa
Diffstat (limited to 'zuul/web')
-rwxr-xr-x | zuul/web/__init__.py | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/zuul/web/__init__.py b/zuul/web/__init__.py index 1b92f1500..e6e1ddb5f 100755 --- a/zuul/web/__init__.py +++ b/zuul/web/__init__.py @@ -29,9 +29,8 @@ import time import select import threading -import re2 - import zuul.lib.repl +from zuul.lib.re2util import filter_allowed_disallowed import zuul.model from zuul import exceptions import zuul.rpcclient @@ -749,21 +748,9 @@ class ZuulWebAPI(object): disallowed_labels = data['disallowed_labels'] labels = set() for launcher in self.zk.getRegisteredLaunchers(): - for label in launcher.supported_labels: - allowed = True - if allowed_labels: - allowed = False - for pattern in allowed_labels: - if re2.match(pattern, label): - allowed = True - break - if disallowed_labels: - for pattern in disallowed_labels: - if re2.match(pattern, label): - allowed = False - break - if allowed: - labels.add(label) + labels.update(filter_allowed_disallowed( + launcher.supported_labels, + allowed_labels, disallowed_labels)) ret = [{'name': label} for label in sorted(labels)] resp = cherrypy.response resp.headers['Access-Control-Allow-Origin'] = '*' |