kopia lustrzana https://github.com/Yakifo/amqtt
Refactor topic_checking to simplify booleans
rodzic
a3f982c4d2
commit
fcba3b6132
|
@ -67,35 +67,35 @@ class TopicAccessControlListPlugin(BaseTopicPlugin):
|
||||||
|
|
||||||
async def topic_filtering(self, *args, **kwargs):
|
async def topic_filtering(self, *args, **kwargs):
|
||||||
filter_result = super().topic_filtering(*args, **kwargs)
|
filter_result = super().topic_filtering(*args, **kwargs)
|
||||||
if filter_result:
|
if not filter_result:
|
||||||
session = kwargs.get("session", None)
|
return False
|
||||||
req_topic = kwargs.get("topic", None)
|
|
||||||
action = kwargs.get("action", None)
|
|
||||||
|
|
||||||
# hbmqtt and older amqtt do not support publish filtering
|
# hbmqtt and older amqtt do not support publish filtering
|
||||||
if action == Action.publish and "publish-acl" not in self.topic_config:
|
action = kwargs.get("action", None)
|
||||||
# maintain backward compatibility, assume permitted
|
if action == Action.publish and "publish-acl" not in self.topic_config:
|
||||||
|
# maintain backward compatibility, assume permitted
|
||||||
|
return True
|
||||||
|
|
||||||
|
req_topic = kwargs.get("topic", None)
|
||||||
|
if not req_topic:
|
||||||
|
return False
|
||||||
|
|
||||||
|
session = kwargs.get("session", None)
|
||||||
|
username = session.username
|
||||||
|
if username is None:
|
||||||
|
username = "anonymous"
|
||||||
|
|
||||||
|
if action == Action.publish:
|
||||||
|
acl = self.topic_config["publish-acl"]
|
||||||
|
elif action == Action.subscribe:
|
||||||
|
acl = self.topic_config["acl"]
|
||||||
|
|
||||||
|
allowed_topics = acl.get(username, None)
|
||||||
|
if not allowed_topics:
|
||||||
|
return False
|
||||||
|
|
||||||
|
for allowed_topic in allowed_topics:
|
||||||
|
if self.topic_ac(req_topic, allowed_topic):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if req_topic:
|
return False
|
||||||
username = session.username
|
|
||||||
if username is None:
|
|
||||||
username = "anonymous"
|
|
||||||
|
|
||||||
if action == Action.publish:
|
|
||||||
acl = self.topic_config["publish-acl"]
|
|
||||||
elif action == Action.subscribe:
|
|
||||||
acl = self.topic_config["acl"]
|
|
||||||
|
|
||||||
allowed_topics = acl.get(username, None)
|
|
||||||
if allowed_topics:
|
|
||||||
for allowed_topic in allowed_topics:
|
|
||||||
if self.topic_ac(req_topic, allowed_topic):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
Ładowanie…
Reference in New Issue