web: add /connections route
This change adds a /connections route to return the list of connections and their configuration. This will be consumable as a way to merge change locally. Change-Id: Ia392faa2aea0740756ccd97f10cccb5aec51545a
This commit is contained in:
parent
62e0c13190
commit
0238c02f38
|
@ -247,6 +247,18 @@ class TestWeb(BaseTestWeb):
|
|||
self.assertEqual(3, data[0]['projects'])
|
||||
self.assertEqual(1, data[0]['queue'])
|
||||
|
||||
def test_web_connections_list(self):
|
||||
data = self.get_url('api/connections').json()
|
||||
connection = {
|
||||
'driver': 'gerrit',
|
||||
'name': 'gerrit',
|
||||
'baseurl': 'https://review.example.com',
|
||||
'canonical_hostname': 'review.example.com',
|
||||
'server': 'review.example.com',
|
||||
'port': 29418,
|
||||
}
|
||||
self.assertEqual([connection], data)
|
||||
|
||||
def test_web_bad_url(self):
|
||||
# do we redirect to index.html
|
||||
resp = self.get_url("status/foo")
|
||||
|
|
|
@ -108,3 +108,11 @@ class BaseConnection(object, metaclass=abc.ABCMeta):
|
|||
Registry of all configured connections.
|
||||
"""
|
||||
return False
|
||||
|
||||
def toDict(self):
|
||||
"""Return public information about the connection
|
||||
"""
|
||||
return {
|
||||
"name": self.connection_name,
|
||||
"driver": self.driver.name,
|
||||
}
|
||||
|
|
|
@ -353,6 +353,16 @@ class GerritConnection(BaseConnection):
|
|||
self.auth = authclass(
|
||||
self.user, self.password)
|
||||
|
||||
def toDict(self):
|
||||
d = super().toDict()
|
||||
d.update({
|
||||
"baseurl": self.baseurl,
|
||||
"canonical_hostname": self.canonical_hostname,
|
||||
"server": self.server,
|
||||
"port": self.port,
|
||||
})
|
||||
return d
|
||||
|
||||
def url(self, path):
|
||||
return self.baseurl + '/a/' + path
|
||||
|
||||
|
|
|
@ -155,6 +155,14 @@ class GitConnection(BaseConnection):
|
|||
self.projects_refs = {}
|
||||
self._change_cache = {}
|
||||
|
||||
def toDict(self):
|
||||
d = super().toDict()
|
||||
d.update({
|
||||
"baseurl": self.baseurl,
|
||||
"canonical_hostname": self.canonical_hostname,
|
||||
})
|
||||
return d
|
||||
|
||||
def getProject(self, name):
|
||||
return self.projects.get(name)
|
||||
|
||||
|
|
|
@ -600,6 +600,15 @@ class GithubConnection(BaseConnection):
|
|||
r"^Depends-On: https://%s/.+/.+/pull/[0-9]+$" % self.server,
|
||||
re.MULTILINE | re.IGNORECASE)
|
||||
|
||||
def toDict(self):
|
||||
d = super().toDict()
|
||||
d.update({
|
||||
"baseurl": self.baseurl,
|
||||
"canonical_hostname": self.canonical_hostname,
|
||||
"server": self.server,
|
||||
})
|
||||
return d
|
||||
|
||||
def onLoad(self):
|
||||
self.log.info('Starting GitHub connection: %s' % self.connection_name)
|
||||
self.gearman_worker = GithubGearmanWorker(self)
|
||||
|
|
|
@ -78,6 +78,7 @@ class RPCListener(object):
|
|||
self.worker.registerFunction("zuul:pipeline_list")
|
||||
self.worker.registerFunction("zuul:key_get")
|
||||
self.worker.registerFunction("zuul:config_errors_list")
|
||||
self.worker.registerFunction("zuul:connection_list")
|
||||
|
||||
def stop(self):
|
||||
self.log.debug("Stopping")
|
||||
|
@ -482,3 +483,9 @@ class RPCListener(object):
|
|||
'source_context': err.key.context.toDict(),
|
||||
'error': err.error})
|
||||
job.sendWorkComplete(json.dumps(output))
|
||||
|
||||
def handle_connection_list(self, job):
|
||||
output = []
|
||||
for source in self.sched.connections.getSources():
|
||||
output.append(source.connection.toDict())
|
||||
job.sendWorkComplete(json.dumps(output))
|
||||
|
|
|
@ -238,6 +238,15 @@ class ZuulWebAPI(object):
|
|||
resp.headers['Access-Control-Allow-Origin'] = '*'
|
||||
return ret
|
||||
|
||||
@cherrypy.expose
|
||||
@cherrypy.tools.json_out(content_type='application/json; charset=utf-8')
|
||||
def connections(self):
|
||||
job = self.rpc.submitJob('zuul:connection_list', {})
|
||||
ret = json.loads(job.data[0])
|
||||
resp = cherrypy.response
|
||||
resp.headers['Access-Control-Allow-Origin'] = '*'
|
||||
return ret
|
||||
|
||||
def _getStatus(self, tenant):
|
||||
with self.status_lock:
|
||||
if tenant not in self.cache or \
|
||||
|
@ -662,6 +671,8 @@ class ZuulWeb(object):
|
|||
api = ZuulWebAPI(self)
|
||||
route_map.connect('api', '/api/info',
|
||||
controller=api, action='info')
|
||||
route_map.connect('api', '/api/connections',
|
||||
controller=api, action='connections')
|
||||
route_map.connect('api', '/api/tenants',
|
||||
controller=api, action='tenants')
|
||||
route_map.connect('api', '/api/tenant/{tenant}/info',
|
||||
|
|
Loading…
Reference in New Issue