mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-19 18:21:03 +02:00
Added auth module, just a simple token at this stage
This commit is contained in:
parent
6d200c79c5
commit
c3fbee4a44
17 changed files with 121 additions and 33 deletions
|
|
@ -11,11 +11,12 @@ logger.setLevel(logging.INFO)
|
|||
class SocketEndpoint:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
endpoint_path="/api/v1/socket",
|
||||
self, endpoint_path, auth,
|
||||
):
|
||||
|
||||
self.path = endpoint_path
|
||||
self.auth = auth
|
||||
self.operation = "socket"
|
||||
|
||||
async def listener(self, ws, running):
|
||||
|
||||
|
|
@ -43,18 +44,33 @@ class SocketEndpoint:
|
|||
|
||||
async def handle(self, request):
|
||||
|
||||
try:
|
||||
token = request.query['token']
|
||||
except:
|
||||
return web.HTTPUnauthorized()
|
||||
|
||||
if not self.auth.permitted(token, self.operation):
|
||||
return web.HTTPUnauthorized()
|
||||
|
||||
running = Running()
|
||||
ws = web.WebSocketResponse()
|
||||
await ws.prepare(request)
|
||||
|
||||
task = asyncio.create_task(self.async_thread(ws, running))
|
||||
|
||||
await self.listener(ws, running)
|
||||
try:
|
||||
|
||||
await task
|
||||
await self.listener(ws, running)
|
||||
|
||||
except Exception as e:
|
||||
print(e, flush=True)
|
||||
|
||||
running.stop()
|
||||
|
||||
await ws.close()
|
||||
|
||||
await task
|
||||
|
||||
return ws
|
||||
|
||||
async def start(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue