refactor(plugin_system): 移除路由级认证,引入端点级安全依赖
之前的插件路由认证机制通过在 `RouterInfo` 中设置 `auth_required` 标志,对整个路由组件统一应用API密钥验证。这种方式缺乏灵活性,无法对单个端点进行细粒度的安全控制。 本次重构移除了 `auth_required` 机制,转而引入一个可重用的 FastAPI 依赖项 `VerifiedDep`。插件开发者现在可以按需将其应用到需要保护的特定端点上,从而实现更灵活、更精确的访问控制。 `hello_world_plugin` 已更新,以演示新的认证方式。 BREAKING CHANGE: 移除了 `RouterInfo` 中的 `auth_required` 属性。所有依赖此属性进行认证的插件路由都需要更新,改为在需要保护的端点上使用 `VerifiedDep` 依赖项。
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from .component_types import ComponentType, RouterInfo
|
||||
|
||||
|
||||
class BaseRouterComponent(ABC):
|
||||
"""
|
||||
用于暴露HTTP端点的组件基类。
|
||||
|
||||
@@ -449,8 +449,6 @@ class MaiMessages:
|
||||
class RouterInfo(ComponentInfo):
|
||||
"""路由组件信息"""
|
||||
|
||||
auth_required: bool = False
|
||||
|
||||
def __post_init__(self):
|
||||
super().__post_init__()
|
||||
self.component_type = ComponentType.ROUTER
|
||||
|
||||
Reference in New Issue
Block a user