新增了插件相关的完整领域模型、应用服务、基础设施实现,包括: 1. 插件状态、注册模式、来源等基础枚举和数据结构 2. 插件清单解析、发现、加载工具类 3. 插件注册表领域服务和内存存储实现 4. 插件相关的命令、查询、事件定义 5. 插件REST API接口和DTO映射 6. 集成了原有通道适配器到插件系统 7. 新增内置插件注册和自动发现能力
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from fastapi import Depends, Header, HTTPException, Query
|
|
|
|
from yuxi.channel.container import ChannelContainer, get_channel
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def channel_auth_depends(
|
|
authorization: str | None = Header(None),
|
|
token_query: str | None = Query(None, alias="token"),
|
|
channel: ChannelContainer = Depends(get_channel),
|
|
) -> bool:
|
|
auth_value = authorization or (f"Bearer {token_query}" if token_query else None)
|
|
|
|
passed, reason = await channel.auth_service.authenticate(
|
|
auth_value or "",
|
|
client_id="mgmt",
|
|
)
|
|
|
|
if not passed:
|
|
if "rate limited" in reason:
|
|
raise HTTPException(status_code=429, detail=reason)
|
|
raise HTTPException(status_code=401, detail=reason or "authorization required")
|
|
|
|
return True
|
|
|
|
|
|
async def channel_auth_operator_depends(
|
|
authorization: str | None = Header(None),
|
|
token_query: str | None = Query(None, alias="token"),
|
|
channel: ChannelContainer = Depends(get_channel),
|
|
) -> str:
|
|
auth_value = authorization or (f"Bearer {token_query}" if token_query else None)
|
|
|
|
passed, reason = await channel.auth_service.authenticate(
|
|
auth_value or "",
|
|
client_id="mgmt",
|
|
)
|
|
|
|
if not passed:
|
|
if "rate limited" in reason:
|
|
raise HTTPException(status_code=429, detail=reason)
|
|
raise HTTPException(status_code=401, detail=reason or "authorization required")
|
|
|
|
return auth_value or "anonymous"
|