新增了插件相关的完整领域模型、应用服务、基础设施实现,包括: 1. 插件状态、注册模式、来源等基础枚举和数据结构 2. 插件清单解析、发现、加载工具类 3. 插件注册表领域服务和内存存储实现 4. 插件相关的命令、查询、事件定义 5. 插件REST API接口和DTO映射 6. 集成了原有通道适配器到插件系统 7. 新增内置插件注册和自动发现能力
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import hmac
|
|
import logging
|
|
|
|
from yuxi.channel.domain.port.channel_request_verifier_port import VerifyResult
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class WebRequestVerifier:
|
|
def __init__(self, *, auth_token: str = "") -> None:
|
|
self._auth_token = auth_token
|
|
|
|
@property
|
|
def channel_type(self) -> str:
|
|
return "web"
|
|
|
|
@property
|
|
def enabled(self) -> bool:
|
|
return bool(self._auth_token)
|
|
|
|
async def verify(self, body: bytes, headers: dict[str, str]) -> VerifyResult:
|
|
if not self._auth_token:
|
|
return VerifyResult(passed=True, method="web_none", reason="no_auth_configured")
|
|
|
|
auth_header = headers.get("authorization", "")
|
|
if auth_header.startswith("Bearer "):
|
|
token = auth_header[7:]
|
|
if hmac.compare_digest(token, self._auth_token):
|
|
return VerifyResult(passed=True, method="web_bearer")
|
|
return VerifyResult(passed=False, method="web_bearer", reason="invalid_bearer_token")
|
|
|
|
return VerifyResult(passed=False, method="web_auth", reason="authentication_required")
|