2025-06-12 12:37:27 +00:00
|
|
|
import logging
|
2025-06-12 14:52:44 +00:00
|
|
|
|
2025-06-12 12:37:27 +00:00
|
|
|
from dataclasses import dataclass
|
|
|
|
|
2025-06-17 16:44:03 +00:00
|
|
|
from amqtt.plugins.base import BasePlugin, BaseAuthPlugin, BaseTopicPlugin
|
2025-06-27 17:59:39 +00:00
|
|
|
from amqtt.contexts import BaseContext, Action
|
2025-06-14 13:51:12 +00:00
|
|
|
|
2025-06-12 12:37:27 +00:00
|
|
|
from amqtt.session import Session
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class TestSimplePlugin(BasePlugin):
|
|
|
|
|
|
|
|
def __init__(self, context: BaseContext):
|
|
|
|
super().__init__(context)
|
|
|
|
|
|
|
|
|
|
|
|
class TestConfigPlugin(BasePlugin):
|
|
|
|
|
|
|
|
def __init__(self, context: BaseContext):
|
|
|
|
super().__init__(context)
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Config:
|
|
|
|
option1: int
|
|
|
|
option2: str
|
2025-07-04 20:05:55 +00:00
|
|
|
option3: int = 20
|
2025-06-12 12:37:27 +00:00
|
|
|
|
|
|
|
|
2025-06-18 16:54:21 +00:00
|
|
|
class TestCoroErrorPlugin(BaseAuthPlugin):
|
|
|
|
|
|
|
|
def authenticate(self, *, session: Session) -> bool | None:
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class TestAuthPlugin(BaseAuthPlugin):
|
2025-06-12 14:52:44 +00:00
|
|
|
|
|
|
|
async def authenticate(self, *, session: Session) -> bool | None:
|
|
|
|
return True
|
|
|
|
|
2025-06-14 13:51:12 +00:00
|
|
|
|
2025-06-18 16:54:21 +00:00
|
|
|
class TestNoAuthPlugin(BaseAuthPlugin):
|
2025-06-12 12:37:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def authenticate(self, *, session: Session) -> bool | None:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2025-06-18 16:54:21 +00:00
|
|
|
class TestAllowTopicPlugin(BaseTopicPlugin):
|
2025-06-12 12:37:27 +00:00
|
|
|
|
|
|
|
def __init__(self, context: BaseContext):
|
|
|
|
super().__init__(context)
|
|
|
|
|
2025-06-18 16:54:21 +00:00
|
|
|
async def topic_filtering(
|
2025-06-12 12:37:27 +00:00
|
|
|
self, *, session: Session | None = None, topic: str | None = None, action: Action | None = None
|
|
|
|
) -> bool:
|
|
|
|
return True
|
2025-06-18 16:54:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestBlockTopicPlugin(BaseTopicPlugin):
|
|
|
|
|
|
|
|
def __init__(self, context: BaseContext):
|
|
|
|
super().__init__(context)
|
|
|
|
|
|
|
|
async def topic_filtering(
|
|
|
|
self, *, session: Session | None = None, topic: str | None = None, action: Action | None = None
|
|
|
|
) -> bool:
|
|
|
|
logger.debug("topic filtering plugin is returning false")
|
|
|
|
return False
|