Sfoglia il codice sorgente

Request direct use test

Hal De 4 anni fa
parent
commit
19f13f3e81
1 ha cambiato i file con 2 aggiunte e 29 eliminazioni
  1. 2 29
      app/app.py

+ 2 - 29
app/app.py

@@ -103,33 +103,6 @@ manager = Manager(
   reconnect_timeout=app.config['AMI_TIMEOUT'],
 )
 
-# class AuthMiddleware:
-  # '''ASGI process middleware that rejects requests missing
-  # the correct authentication header'''
-
-  # def __init__(self, app):
-    # self.app = app
-  # async def __call__(self, scope, receive, send):
-    # if 'headers' not in scope:
-      # return await self.app(scope, receive, send)
-    # for header, value in scope['headers']:
-      # 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)
-    # # Paths "/openapi.json" and "/ui" do not require auth
-    # if (('path' in scope) and
-        # ((scope['path'] in NO_AUTH_ROUTES) or
-         # (scope['path'].startswith('/static/records')))):
-      # return await self.app(scope, receive, send)
-    # return await self.error_response(receive, send)
-  # async def error_response(self, receive, send):
-    # await send({'type': 'http.response.start',
-                # 'status': 401,
-                # 'headers': [(b'content-length', b'21')]})
-    # await send({'type': 'http.response.body',
-                # 'body': b'Authorization requred',
-                # 'more_body': False})
-
 def authRequired(func):
   @wraps(func)
   async def authWrapper(*args, **kwargs):
@@ -139,6 +112,7 @@ def authRequired(func):
         (auth.type == "basic") and
         (auth.username in current_app.cache['devices']) and
         (compare_digest(auth.password, current_app.cache['devices'][auth.username]))):
+      request.device = auth.username
       return await func(*args, **kwargs)
     elif ((current_app.config['AUTH_HEADER'].lower() in headers) and
           (headers[current_app.config['AUTH_HEADER'].lower()] == current_app.config['AUTH_SECRET'])):
@@ -147,7 +121,6 @@ def authRequired(func):
       abort(401)
   return authWrapper
 
-# app.asgi_app = AuthMiddleware(app.asgi_app)
 db = PintDB(app)
 
 @manager.register_event('FullyBooted')
@@ -313,7 +286,6 @@ async def amiGetVar(variable):
 @authRequired
 @app.route('/ami/auths')
 async def amiPJSIPShowAuths():
-  app.logger.warning(pformat(request.headers))
   return successReply(app.cache['devices'])
 
 @authRequired
@@ -781,6 +753,7 @@ class UsersStates(Resource):
     '''Returns all users with their combined states.
     Possible states are: available, away, dnd, inuse, busy, unavailable, ringing
     '''
+    app.logger.warning('request device: {}'.format(request.device))
     usersCount = await refreshStatesCache()
     if usersCount == 0:
       return stateCacheEmpty()