Bladeren bron

Minor bug fixes & APP_EXTRA_API_URL option

Hal De 4 jaren geleden
bovenliggende
commit
e2ea5c795b
3 gewijzigde bestanden met toevoegingen van 13 en 6 verwijderingen
  1. 1 0
      app.env.dist
  2. 10 4
      app/app.py
  3. 2 2
      app/utils.py

+ 1 - 0
app.env.dist

@@ -13,3 +13,4 @@ APP_AMI_TIMEOUT=5
 APP_AUTH_HEADER=APP-auth-token
 APP_AUTH_SECRET=secret
 #APP_STATE_CALLBACK_URL=
+#APP_EXTRA_API_URL=

+ 10 - 4
app/app.py

@@ -38,6 +38,7 @@ app.config.update({
   'SWAGGER_JS_URL':         os.getenv('APP_SWAGGER_JS_URL', SWAGGER_JS_URL),
   'SWAGGER_CSS_URL':        os.getenv('APP_SWAGGER_CSS_URL', SWAGGER_CSS_URL),
   'STATE_CALLBACK_URL':     os.getenv('APP_STATE_CALLBACK_URL', None),
+  'EXTRA_API_URL':          os.getenv('APP_EXTRA_API_URL', None),
   'STATE_CACHE':           {'user':{},
                             'presence':{}}})
 
@@ -118,6 +119,8 @@ async def openapi():
   schema['servers'] = [{'url':'{}://{}:{}'.format(app.config['SCHEME'],
                                                   app.config['FQDN'],
                                                   app.config['PORT'])}]
+  if app.config['EXTRA_API_URL'] is not None:
+    schema['servers'].append({'url':app.config['EXTRA_API_URL']})
   schema['components'] = {'securitySchemes':{'ApiKey':{'type': 'apiKey',
                                                        'name': app.config['AUTH_HEADER'],
                                                        'in': 'header'}}}
@@ -450,11 +453,14 @@ def getUserStateCombined(user):
   if user not in app.config['STATE_CACHE']['user']:
     return None
   _state = app.config['STATE_CACHE']['user'][user]
-  if (_state == 'idle') and (user in app.config['STATE_CACHE']['presence']):
-    if app.config['STATE_CACHE']['presence'][user] in ('not_set','available', 'xa', 'chat'):
-      return 'available'
+  if (_state == 'idle'):
+    if (user in app.config['STATE_CACHE']['presence']):
+      if app.config['STATE_CACHE']['presence'][user] in ('not_set','available', 'xa', 'chat'):
+        return 'available'
+      else:
+        return app.config['STATE_CACHE']['presence'][user]
     else:
-      return app.config['STATE_CACHE']['presence'][user]
+      return 'available'
   else:
     if _state in ('unavailable', 'ringing'):
       return _state

+ 2 - 2
app/utils.py

@@ -47,8 +47,8 @@ class QueueMember:
   stateinterface: str = ''
   status: str = ''
   def fromMessage(self, _m: Message):
-    for key in asdict(self):
-      if key in _m.getdict():
+    for key in asdict(self).keys():
+      if key in _m:
         setattr(self, key, _m[key])
     return self