Use message and subscriptions host to filter notifications
authorThierry Florac <tflorac@ulthar.net>
Wed, 26 Jun 2019 18:58:58 +0200
changeset 25 bdb57ba75245
parent 24 4f59f94ad901
child 26 e2ce53e66fc9
Use message and subscriptions host to filter notifications
src/pyams_notify_ws/notify.py
--- a/src/pyams_notify_ws/notify.py	Wed Jun 26 18:58:19 2019 +0200
+++ b/src/pyams_notify_ws/notify.py	Wed Jun 26 18:58:58 2019 +0200
@@ -55,6 +55,7 @@
             action = message.get('action')
             if action == 'notify':
                 # dispatch notification to subscribers
+                host = message.get('host')
                 source = message.get('source', {}).get('id')
                 target = message.get('target', {}).get('principals', ())
                 clean_message = message.copy()
@@ -62,6 +63,9 @@
                 json_message = json.dumps(clean_message)
                 async with users_lock:
                     for connection, subscription in users.items():
+                        # don't send notification to other hosts
+                        if host and (host != subscription.host):
+                            continue
                         # don't send notification to emitter
                         if source and (source == subscription.principal['id']):
                             continue