API for single host provides same data as List.
This commit is contained in:
parent
6fd075dd16
commit
b1ed741394
@ -173,13 +173,20 @@ class UserCert(object):
|
|||||||
resp.status = falcon.HTTP_OK
|
resp.status = falcon.HTTP_OK
|
||||||
|
|
||||||
|
|
||||||
def hostToJson(host):
|
def _hostAsDict(host):
|
||||||
return json.dumps({
|
item = {
|
||||||
'host_id': host.host_id,
|
'host_id': host.host_id,
|
||||||
'fingerprint': host.fingerprint,
|
'fingerprint': host.fingerprint,
|
||||||
'auth_id': host.auth_id,
|
'auth_id': host.auth_id,
|
||||||
'cert': host.cert,
|
'cert': host.cert,
|
||||||
})
|
'hostname': host.hostname,
|
||||||
|
}
|
||||||
|
if CONF.tatu.use_pat_bastions:
|
||||||
|
item['pat_bastions'] = ','.join(
|
||||||
|
'{}:{}'.format(t[1], t[0]) for t in
|
||||||
|
get_port_ip_tuples(host.host_id, 22))
|
||||||
|
item['srv_url'] = get_srv_url(host.hostname, host.auth_id)
|
||||||
|
return item
|
||||||
|
|
||||||
|
|
||||||
class HostCerts(object):
|
class HostCerts(object):
|
||||||
@ -196,7 +203,7 @@ class HostCerts(object):
|
|||||||
)
|
)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
raise falcon.HTTPBadRequest(str(e))
|
raise falcon.HTTPBadRequest(str(e))
|
||||||
resp.body = hostToJson(host)
|
resp.body = json.dumps(_hostAsDict(host))
|
||||||
resp.status = falcon.HTTP_200
|
resp.status = falcon.HTTP_200
|
||||||
resp.location = '/hostcerts/' + host.host_id + '/' + host.fingerprint
|
resp.location = '/hostcerts/' + host.host_id + '/' + host.fingerprint
|
||||||
|
|
||||||
@ -205,20 +212,7 @@ class HostCerts(object):
|
|||||||
hosts = db.getHostCerts(self.session)
|
hosts = db.getHostCerts(self.session)
|
||||||
items = []
|
items = []
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
item = {
|
items.append(_hostAsDict(host))
|
||||||
'host_id': host.host_id,
|
|
||||||
'fingerprint': host.fingerprint,
|
|
||||||
'auth_id': host.auth_id,
|
|
||||||
'cert': host.cert,
|
|
||||||
'hostname': host.hostname,
|
|
||||||
}
|
|
||||||
if CONF.tatu.use_pat_bastions:
|
|
||||||
item['pat_bastions'] = ','.join(
|
|
||||||
'{}:{}'.format(t[1], t[0]) for t in
|
|
||||||
get_port_ip_tuples(host.host_id, 22))
|
|
||||||
item['srv_url'] = get_srv_url(host.hostname, host.auth_id)
|
|
||||||
items.append(item)
|
|
||||||
|
|
||||||
body = {'hosts': items}
|
body = {'hosts': items}
|
||||||
resp.body = json.dumps(body)
|
resp.body = json.dumps(body)
|
||||||
resp.status = falcon.HTTP_OK
|
resp.status = falcon.HTTP_OK
|
||||||
@ -231,7 +225,7 @@ class HostCert(object):
|
|||||||
if host is None:
|
if host is None:
|
||||||
resp.status = falcon.HTTP_NOT_FOUND
|
resp.status = falcon.HTTP_NOT_FOUND
|
||||||
return
|
return
|
||||||
resp.body = hostToJson(host)
|
resp.body = json.dumps(_hostAsDict(host))
|
||||||
resp.status = falcon.HTTP_OK
|
resp.status = falcon.HTTP_OK
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user