Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have developed a new version of HBMQTT which supports topic filtering. This is: you can define a topic filtering plugin in order to grant or deny subscriptions to certain topics, depending on the policy you want.
For that, I have created the
hbmqtt/plugins/topic_checking.py
file, where I developed a very silly topic filtering policy: If you want to subscribe toprohibited
,top-secret
ordata/classified
topics, your username must beadmin
. Otherwise, you will not be subscribed. You may take this example as a template for designing your own topic policy.How to try it
After downloading this fork, execute the following python commands on the hbmqtt directory:
You can notice that this commit also adds a line in this script: This is necessary for the namespace to being able to detect the new plugin.
After that, you will execute three processes:
python3 samples/broker_taboo.py
This starts an MQTT broker with topic_taboo plugin enabled. This can be configured via the configuration parameter of the broker:
python3 samples/client_subscribe_taboo.py
This starts an MQTT client that will try to subscribe to a valid topic and a forbidden topic
python3 samples/client_publish_taboo.py
This starts an MQTT client that will publish two messages in the valid and the forbidden topic.
The console of the client subscribed will only receive the valid message.