From 77cf4555e94a83b245c5e21c5eb83ac387c5d299 Mon Sep 17 00:00:00 2001 From: Kevin Zhao Date: Fri, 19 May 2017 16:54:07 +0800 Subject: [PATCH] Change the uuid from websocket header to querystring That will be easy for zun-ui to prase. Implements: blueprint stream-via-rest-api Change-Id: Ibdf5067c94a259c86eae274b411bd66e696f03dc Signed-off-by: Kevin Zhao --- zun/compute/manager.py | 3 ++- zun/websocket/websocketproxy.py | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/zun/compute/manager.py b/zun/compute/manager.py index 884ebf417..9afbd84a7 100755 --- a/zun/compute/manager.py +++ b/zun/compute/manager.py @@ -403,7 +403,8 @@ class Manager(object): try: url = self.driver.get_websocket_url(container) token = uuidutils.generate_uuid() - access_url = '%s?token=%s' % (CONF.websocket_proxy.base_url, token) + access_url = '%s?token=%s&uuid=%s' % ( + CONF.websocket_proxy.base_url, token, container.uuid) container.websocket_url = url container.websocket_token = token container.save(context) diff --git a/zun/websocket/websocketproxy.py b/zun/websocket/websocketproxy.py index 3ed036c28..2e6cdb9e7 100644 --- a/zun/websocket/websocketproxy.py +++ b/zun/websocket/websocketproxy.py @@ -188,20 +188,21 @@ class ZunProxyRequestHandlerBase(object): query = parse.query token = urlparse.parse_qs(query).get("token", [""]).pop() + uuid = urlparse.parse_qs(query).get("uuid", [""]).pop() dbapi = db_api._get_dbdriver_instance() ctx = context.get_admin_context(all_tenants=True) - self.headerid = self.headers.get("User-Agent") - if uuidutils.is_uuid_like(self.headerid): - container = dbapi.get_container_by_uuid(ctx, self.headerid) + if uuidutils.is_uuid_like(uuid): + container = dbapi.get_container_by_uuid(ctx, uuid) else: - container = dbapi.get_container_by_name(ctx, self.headerid) + container = dbapi.get_container_by_name(ctx, uuid) if token != container.websocket_token: raise exception.InvalidWebsocketToken(token) - access_url = '%s?token=%s' % (CONF.websocket_proxy.base_url, token) + access_url = '%s?token=%s&uuid=%s' % (CONF.websocket_proxy.base_url, + token, uuid) # Verify Origin expected_origin_hostname = self.headers.get('Host')