- 绑定新增 param_mapping_json:域参数→接口参数声明式映射(map_response 规范),空对象同名直通 - 凭据引用新增 db 维护模式:secret_ciphertext Fernet 加密落库,主密钥 INTEGRATION_CREDENTIAL_KEY 仅环境注入,与 env 引用模式并存 - 新增 credential_types 凭据形态注册表:代码注册各类型字段清单,UI 动态渲染与 API 组装校验的唯一事实来源 - 移除绑定 context_source_code 独立列,路由条件统一 context_selector_json - 管理端表单 Modal 重构为 Drawer,新增 JSON 编辑字段组件与页面级测试 - 迁移 rd1/re1 重挂当前唯一 head dd22ee33ff44,维持单 head 链 - settings 移除 IN_TRANSIT_TRANSFER_ERP_* 配置,外部端点/凭据移交连接器客户端实例管理
60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
"""services/integration_connector/capability.py
|
||
|
||
用途:Capability 强类型契约注册表(能力名称/输入输出 Schema/幂等语义/是否写)。
|
||
依赖:app.core.errors、errors.py;纯代码,不依赖 DB。
|
||
逻辑:能力必须由代码注册,不能由管理端动态定义;各域契约声明在各域包的
|
||
capabilities 模块(如 in_transit_transfer/capabilities.py),由应用组合根
|
||
import 完成注册;领域只调用已注册能力,未注册 fail-closed。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from dataclasses import dataclass
|
||
|
||
from app.core.errors import ValidationError
|
||
from app.services.integration_connector.errors import CapabilityNotFoundError
|
||
|
||
|
||
@dataclass(frozen=True)
|
||
class CapabilitySpec:
|
||
"""强类型能力契约(由代码注册)。"""
|
||
|
||
name: str
|
||
input_schema: dict
|
||
output_schema: dict
|
||
idempotency: str
|
||
write: bool
|
||
|
||
|
||
_CAPABILITIES: dict[str, CapabilitySpec] = {}
|
||
|
||
|
||
def register_capability(spec: CapabilitySpec) -> CapabilitySpec:
|
||
"""注册能力;同名重复注册抛 ValidationError。"""
|
||
if spec.name in _CAPABILITIES:
|
||
raise ValidationError(
|
||
f"capability already registered: {spec.name}",
|
||
code="INTEGRATION.CAPABILITY_DUPLICATE",
|
||
details={"name": spec.name},
|
||
)
|
||
_CAPABILITIES[spec.name] = spec
|
||
return spec
|
||
|
||
|
||
def get_capability(name: str) -> CapabilitySpec:
|
||
"""按名查询能力;未注册抛 CapabilityNotFoundError(fail-closed)。"""
|
||
spec = _CAPABILITIES.get(name)
|
||
if spec is None:
|
||
raise CapabilityNotFoundError(name=name)
|
||
return spec
|
||
|
||
|
||
def list_capabilities() -> list[CapabilitySpec]:
|
||
"""返回全部已注册能力(按名排序)。"""
|
||
return sorted(_CAPABILITIES.values(), key=lambda s: s.name)
|
||
|
||
|
||
def reset_capability_registry_for_tests() -> None:
|
||
"""单测隔离:清空注册表(领域 capabilities 模块可重调其注册函数重建)。"""
|
||
_CAPABILITIES.clear()
|