Bläddra i källkod

originate test

Hal De 4 år sedan
förälder
incheckning
792d38367b
1 ändrade filer med 18 tillägg och 12 borttagningar
  1. 18 12
      app/app.py

+ 18 - 12
app/app.py

@@ -17,6 +17,8 @@ from panoramisk import Manager, Message
 from utils import *
 from cel import *
 from logging.config import dictConfig
+from pprint import pformat
+from inspect import getmembers
 
 class ApiJsonEncoder(JSONEncoder):
   def default(self, o):
@@ -112,6 +114,12 @@ class AuthMiddleware:
       if ((header == bytes(app.config['AUTH_HEADER'].lower(), 'utf-8')) and
           (value == bytes(app.config['AUTH_SECRET'], 'utf-8'))):
         return await self.app(scope, receive, send)
+      for device in app.cache['devices']:
+        if ((header == bytes('{}_{}'.format(app.config['AUTH_HEADER'].lower(), device), 'utf-8')) and
+            (value == bytes(app.cache['devices'][device], 'utf-8'))):
+          self.app.logger.warning('scope: {}'.format(pformat(getmembers(scope), indent=1)))
+          self.app.logger.warning('request: {}'.format(pformat(getmembers(request), indent=1)))
+          return await self.app(scope, receive, send)
     # Paths "/openapi.json" and "/ui" do not require auth
     if (('path' in scope) and
         ((scope['path'] in NO_AUTH_ROUTES) or
@@ -290,15 +298,7 @@ async def amiGetVar(variable):
 
 @app.route('/ami/auths')
 async def amiPJSIPShowAuths():
-  auths = {}
-  reply = await manager.send_action({'Action':'PJSIPShowAuths'})
-  if len(reply) >= 2:
-    for message in reply:
-      if ((message.event == 'AuthList') and
-          ('objecttype' in message) and
-          (message.objecttype == 'auth')):
-        auths[message.username] = message.password
-  return successReply(auths)
+  return successReply(app.cache['devices'])
 
 @app.route('/ami/aors')
 async def amiPJSIPShowAors():
@@ -614,9 +614,15 @@ async def refreshStatesCache():
   return len(app.cache['ustates'])
 
 async def refreshDevicesCache():
-  _reply = await amiPJSIPShowAors()
-  aors = _reply['data']
-  app.cache['devices'] = list(aors.keys())
+  auths = {}
+  reply = await manager.send_action({'Action':'PJSIPShowAuths'})
+  if len(reply) >= 2:
+    for message in reply:
+      if ((message.event == 'AuthList') and
+          ('objecttype' in message) and
+          (message.objecttype == 'auth')):
+        auths[message.username] = message.password
+  app.cache['devices'] = auths
   return len(app.cache['devices'])
 
 async def refreshQueuesCache():