Unverified Commit 0cc9004a authored by joelei's avatar joelei
Browse files

finish log stream

No related merge requests found
Showing with 14 additions and 2 deletions
+14 -2
......@@ -12,6 +12,7 @@
# specific language governing permissions and limitations under the License.
#
import logging
import re
from urllib import parse
from channels.auth import AuthMiddlewareStack
......@@ -66,9 +67,18 @@ class RequestProvider(object):
class ChannelSessionAuthMiddleware:
"""django channel auth middleware"""
CHANNEL_URL_PATTERN = re.compile(r'/projects/(?P<project_id>\w{32})/clusters/(?P<cluster_id>[\w\-]+)/')
def __init__(self, inner):
self.inner = inner
def extract_project_and_cluster_id(self, scope):
pattern = re.findall(self.CHANNEL_URL_PATTERN, scope['path'])
if len(pattern) == 0:
raise HttpResponseForbidden(_("url中project_id或者cluster_id为空"))
return pattern[0]
async def __call__(self, scope, receive, send):
query_params = dict(parse.parse_qsl(scope['query_string'].decode('utf8')))
......@@ -76,7 +86,9 @@ class ChannelSessionAuthMiddleware:
if not session_id:
raise HttpResponseForbidden(_("session_id为空"))
session = session_mgr.create("", "")
project_id, cluster_id = self.extract_project_and_cluster_id(scope)
session = session_mgr.create(project_id, cluster_id)
ctx = session.get(session_id)
if not ctx:
raise HttpResponseForbidden(_("获取ctx为空, session_id不正确或者已经过期"))
......
......@@ -72,7 +72,7 @@ class LogStreamViewSet(SystemViewSet):
'cluster_id': cluster_id,
}
session = session_mgr.create("", "")
session = session_mgr.create(project_id, cluster_id)
session_id = session.set(ctx)
stream_url = (
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment