diff options
author | Tristan Cacqueray <tdecacqu@redhat.com> | 2019-04-19 01:52:30 +0000 |
---|---|---|
committer | Tristan Cacqueray <tdecacqu@redhat.com> | 2019-04-19 02:01:09 +0000 |
commit | d32a870a4fcb5ea6adfc02bc828113aa99572e38 (patch) | |
tree | c0797787fe3fc637a1cb51b863a6413b042f52de /zuul/web | |
parent | dc9347c1223e3c7eb0399889d03c5de9e854a836 (diff) | |
download | zuul-d32a870a4fcb5ea6adfc02bc828113aa99572e38.tar.gz |
web: honor allowed-labels setting in the REST API
This change adds a new gearman method to get the allowed-labels setting
so that the web service can filter the list of available labels per
tenant.
Change-Id: I5b1f9a19340b98d4100ffe8e904b434851b50293
Diffstat (limited to 'zuul/web')
-rwxr-xr-x | zuul/web/__init__.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/zuul/web/__init__.py b/zuul/web/__init__.py index 140d6f380..5c86a8901 100755 --- a/zuul/web/__init__.py +++ b/zuul/web/__init__.py @@ -29,6 +29,8 @@ import time import select import threading +import re2 + import zuul.model import zuul.rpcclient import zuul.zk @@ -394,10 +396,17 @@ class ZuulWebAPI(object): @cherrypy.tools.save_params() @cherrypy.tools.json_out(content_type='application/json; charset=utf-8') def labels(self, tenant): + job = self.rpc.submitJob('zuul:allowed_labels_get', {'tenant': tenant}) + allowed_labels = json.loads(job.data[0]) + if allowed_labels is None: + raise cherrypy.HTTPError(404, 'Tenant %s does not exist.' % tenant) labels = set() for launcher in self.zk.getRegisteredLaunchers(): for label in launcher.supported_labels: - labels.add(label) + if not allowed_labels or ( + [True for allowed_label in allowed_labels if + re2.match(allowed_label, label)]): + labels.add(label) ret = [{'name': label} for label in sorted(labels)] resp = cherrypy.response resp.headers['Access-Control-Allow-Origin'] = '*' |