How to implement application specific plugins for amqtt?
FlyingDiver opened this issue · 1 comments
I'm not familiar with Poetry, but it appears that the mapping from plugin name in the config file to the actual code implementation is specified in pyproject.toml:
[tool.poetry.plugins."amqtt.broker.plugins"]
"event_logger_plugin" = "amqtt.plugins.logging:EventLoggerPlugin"
"packet_logger_plugin" = "amqtt.plugins.logging:PacketLoggerPlugin"
"auth_anonymous" = "amqtt.plugins.authentication:AnonymousAuthPlugin"
"auth_file" = "amqtt.plugins.authentication:FileAuthPlugin"
"topic_taboo" = "amqtt.plugins.topic_checking:TopicTabooPlugin"
"topic_acl" = "amqtt.plugins.topic_checking:TopicAccessControlListPlugin"
"broker_sys" = "amqtt.plugins.sys.broker:BrokerSysPlugin"
But pyproject.toml is not part of the actual amqtt library, just the Git repository. How does that actually work at run time? I have need to implement a different Auth plugin, but I can't figure out how to specify it in the config file.
AFAIK
As you mentioned, the config contains the entry point specification.
If you want to know how this works under the hood, see https://packaging.python.org/en/latest/specifications/entry-points/
If you want to use entry points with particular names, your own project must include its own configuration, e.g. with a section in your projects pyproject.toml
E.g. if you also use poetry
[tool.poetry.plugins."amqtt.broker.plugins"]
"custom_plugin" = "my_project.amqtt_plugins.CustomPlugin"
If you do not use poetry
or pyproject.toml
see
https://setuptools.pypa.io/en/latest/userguide/entry_point.html#entry-points-for-plugins
Then you can reference your plugin by name in the relevant configuration, e.g.
broker_config = {
auth: {
plugins: ["custom_plugin"]
}
}
broker = amqtt.broker.Broker(config=broker_config)