Merge "web: add /{tenant}/pipelines route"

This commit is contained in:
Zuul 2018-09-21 03:34:32 +00:00 committed by Gerrit Code Review
commit 507be8c5bf
3 changed files with 37 additions and 0 deletions

View File

@ -372,6 +372,17 @@ class TestWeb(BaseTestWeb):
'voting': True
}], data)
def test_web_pipeline_list(self):
# can we fetch the list of pipelines
data = self.get_url('api/tenant/tenant-one/pipelines').json()
expected_list = [
{'name': 'check'},
{'name': 'gate'},
{'name': 'post'},
]
self.assertEqual(expected_list, data)
def test_web_project_list(self):
# can we fetch the list of projects
data = self.get_url('api/tenant/tenant-one/projects').json()

View File

@ -73,6 +73,7 @@ class RPCListener(object):
self.worker.registerFunction("zuul:job_list")
self.worker.registerFunction("zuul:project_get")
self.worker.registerFunction("zuul:project_list")
self.worker.registerFunction("zuul:pipeline_list")
self.worker.registerFunction("zuul:key_get")
self.worker.registerFunction("zuul:config_errors_list")
@ -441,6 +442,17 @@ class RPCListener(object):
job.sendWorkComplete(json.dumps(
sorted(output, key=lambda project: project["name"])))
def handle_pipeline_list(self, job):
args = json.loads(job.arguments)
tenant = self.sched.abide.tenants.get(args.get("tenant"))
if not tenant:
job.sendWorkComplete(json.dumps(None))
return
output = []
for pipeline in tenant.layout.pipelines.keys():
output.append({"name": pipeline})
job.sendWorkComplete(json.dumps(output))
def handle_key_get(self, job):
args = json.loads(job.arguments)
tenant = self.sched.abide.tenants.get(args.get("tenant"))

View File

@ -332,6 +332,18 @@ class ZuulWebAPI(object):
resp.headers['Access-Control-Allow-Origin'] = '*'
return ret
@cherrypy.expose
@cherrypy.tools.save_params()
@cherrypy.tools.json_out(content_type='application/json; charset=utf-8')
def pipelines(self, tenant):
job = self.rpc.submitJob('zuul:pipeline_list', {'tenant': tenant})
ret = json.loads(job.data[0])
if ret is None:
raise cherrypy.HTTPError(404, 'Tenant %s does not exist.' % tenant)
resp = cherrypy.response
resp.headers['Access-Control-Allow-Origin'] = '*'
return ret
@cherrypy.expose
@cherrypy.tools.save_params()
def key(self, tenant, project):
@ -562,6 +574,8 @@ class ZuulWeb(object):
controller=api, action='projects')
route_map.connect('api', '/api/tenant/{tenant}/project/{project:.*}',
controller=api, action='project')
route_map.connect('api', '/api/tenant/{tenant}/pipelines',
controller=api, action='pipelines')
route_map.connect('api', '/api/tenant/{tenant}/key/{project:.*}.pub',
controller=api, action='key')
route_map.connect('api', '/api/tenant/{tenant}/'