feat(integration-connector): database 传输类型、两步绑定编排与调用日志捕获查询
- 新增 database 传输:直连 MySQL/Oracle/SQLServer/PostgreSQL 执行绑定 SQL(新增 pymysql/pymssql 驱动依赖) - 绑定支持 steps_json 多步编排:每步独立传输调用与审计,无 steps 的既有绑定走单步兼容路径 - 客户端实例校验 connector_type ∈ rest/soap/database,database 强制 db_kind 白名单,非 database 置空 - 三个传输层捕获线级事实(最终 SQL/渲染后 XML/原始响应)随调用记录落库,引擎可选透传 business_ref 业务锚点 - 新增调用日志查询 API(列表/详情/同 operation 步骤时间线,仅管理员)与管理端「调用日志」tab:筛选、双栏对照、外部工具复现命令 - 迁移 tt7a/tta9/tt5b:连接器类型枚举、绑定 steps_json、放开 calls 操作唯一约束 - 说明:wire_json 列迁移挂链尾(依赖域表迁移),随后续批次单独落地
This commit is contained in:
1 parent
8a814e7152
commit
e750fa8602
47 files changed
+7441
-353
No files matched your search
@@ -1,11 +1,13 @@
|
||||
"""models/integration_connector.py
|
||||
|
||||
用途:Integration Connector(外部系统连接器框架)P1 配置与运行时模型:
|
||||
用途:Integration Connector(外部系统连接器框架)配置与运行时模型:
|
||||
CredentialReference、ClientInstance、InterfaceDefinition、Binding、Call。
|
||||
依赖:models.base.Base、SQLAlchemy 2.0 ORM。
|
||||
逻辑:配置层实体(CredentialReference/ClientInstance/InterfaceDefinition/Binding)
|
||||
维护版本与状态;IntegrationCall 记录一次技术调用事实(冻结绑定版本 + 脱敏摘要)。
|
||||
连接器类型(rest/soap)与状态均用 CheckConstraint 兜底,fail-closed 语义在服务层。
|
||||
连接器类型(rest/soap/database)与状态均用 CheckConstraint 兜底;database 客户端
|
||||
另有 db_kind 专列(mysql/oracle/sqlserver/postgresql),fail-closed 语义在服务层。
|
||||
Binding.steps_json 表达一对多有序接口配方(D10);旧单步列保留至 P2。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -31,8 +33,10 @@ from sqlalchemy.dialects.postgresql import JSONB
|
||||
|
||||
from app.models.base import Base
|
||||
|
||||
# P1 仅落地 REST/SOAP;后续扩 RPA/SQL/FILE 时放宽约束并新建迁移。
|
||||
CONNECTOR_TYPES = ('rest', 'soap')
|
||||
# 连接器类型白名单;模型 CHECK 由本常量动态生成,扩枚举须配套 Alembic 迁移重建 CHECK。
|
||||
CONNECTOR_TYPES = ('rest', 'soap', 'database')
|
||||
# database 专属库种(D16):专列 db_kind,非 config_json;API/transport 同源 fail-closed。
|
||||
DB_KINDS = ('mysql', 'oracle', 'sqlserver', 'postgresql')
|
||||
CONFIG_STATUSES = ('draft', 'published', 'retired')
|
||||
CREDENTIAL_STATUSES = ('active', 'rotating', 'retired')
|
||||
|
||||
@@ -89,9 +93,12 @@ class IntegrationClientInstance(Base):
|
||||
connector_type: Mapped[str] = mapped_column(String(16), nullable=False)
|
||||
environment: Mapped[str] = mapped_column(String(16), nullable=False, default='prod', server_default='prod')
|
||||
# 关键强类型字段独立列(JSON 保留作兜底;兼容层 binding.py 拼回 dict)。
|
||||
# endpoint = 连接地址:REST 为接口基地址,SOAP 为 WSDL 地址(WSDL 内含服务端点)。
|
||||
# endpoint = 连接地址:REST 为接口基地址,SOAP 为 WSDL 地址(WSDL 内含服务端点);
|
||||
# database 为 host:port[/database|service_name]。
|
||||
endpoint: Mapped[Optional[str]] = mapped_column(String(512), nullable=True)
|
||||
timeout_seconds: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
|
||||
# database 专属库种(仅 connector_type='database' 有值;rest/soap 为 NULL)。
|
||||
db_kind: Mapped[Optional[str]] = mapped_column(String(32), nullable=True)
|
||||
config_json: Mapped[dict[str, Any]] = mapped_column(JSON, nullable=False, default=dict)
|
||||
credential_ref_code: Mapped[Optional[str]] = mapped_column(
|
||||
ForeignKey('integration_credential_references.code'), nullable=True,
|
||||
@@ -144,7 +151,12 @@ class IntegrationInterfaceDefinition(Base):
|
||||
|
||||
|
||||
class IntegrationBinding(Base):
|
||||
"""绑定:(Capability, context_selector) → 客户端 + 接口 + 映射版本;版本化、可发布、可退役。"""
|
||||
"""绑定:(Capability, context_selector) → 有序接口步骤配方;版本化、可发布、可退役。
|
||||
|
||||
一对多有序(D10/D13):steps_json = [{interface_code, param_mapping_json}, ...];
|
||||
每步客户端由接口归属自带。旧列 interface_definition_code / param_mapping_json /
|
||||
client_instance_code 迁移后保留镜像首步,解析不再读取,P2 删除。
|
||||
"""
|
||||
|
||||
__tablename__ = 'integration_bindings'
|
||||
__table_args__ = (
|
||||
@@ -165,8 +177,11 @@ class IntegrationBinding(Base):
|
||||
capability: Mapped[str] = mapped_column(String(128), nullable=False)
|
||||
# 路由条件(来源/组织/租户等键值对;空对象 = 默认绑定):须为调用 context 的子集才命中。
|
||||
context_selector_json: Mapped[dict[str, Any]] = mapped_column(CONTEXT_SELECTOR_JSON, nullable=False, default=dict)
|
||||
# 域参数 → 接口参数的声明式映射(map_response 规范:{接口参数: {expr/template/transform/args}});
|
||||
# 空对象 = 域参数同名直通。结构属绑定(capability↔接口的翻译契约),不属接口定义。
|
||||
# 有序步骤配方:每步 {interface_code, param_mapping_json};客户端由接口归属推导。
|
||||
steps_json: Mapped[list[dict[str, Any]]] = mapped_column(
|
||||
CONTEXT_SELECTOR_JSON, nullable=False, default=list,
|
||||
)
|
||||
# 域参数 → 接口参数的声明式映射(旧单步列,P2 删;迁移后镜像 steps_json[0])。
|
||||
# 与 context_selector_json 同用 JSONB variant(PostgreSQL)保持表内 JSON 列类型一致。
|
||||
param_mapping_json: Mapped[dict[str, Any]] = mapped_column(CONTEXT_SELECTOR_JSON, nullable=False, default=dict)
|
||||
client_instance_code: Mapped[str] = mapped_column(
|
||||
@@ -188,13 +203,20 @@ class IntegrationBinding(Base):
|
||||
|
||||
|
||||
class IntegrationCall(Base):
|
||||
"""一次技术调用事实:冻结绑定版本 + 脱敏请求/响应摘要,供审计与追溯。"""
|
||||
"""一次技术调用事实:冻结绑定版本 + 脱敏请求/响应摘要,供审计与追溯。
|
||||
|
||||
多步顺序引擎(Task 4)一次能力调用按步骤落 N 条审计、共享同一 operation_id
|
||||
(一票一次执行 = N 条,按 operation_id 串联 + binding_snapshot_json.step_index
|
||||
定位),故 operation_id 无唯一约束;原唯一约束兼作的索引由普通索引
|
||||
ix_integration_calls_operation_id 补回(迁移 tt5b6c7d8e9f)。
|
||||
"""
|
||||
|
||||
__tablename__ = 'integration_calls'
|
||||
__table_args__ = (
|
||||
UniqueConstraint('operation_id', name='uq_integration_calls_operation_id'),
|
||||
Index('ix_integration_calls_operation_id', 'operation_id'),
|
||||
Index('ix_integration_calls_capability_created', 'capability', 'created_at'),
|
||||
Index('ix_integration_calls_trace_id', 'trace_id'),
|
||||
Index('ix_integration_calls_business_ref', 'business_ref'),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
@@ -206,4 +228,9 @@ class IntegrationCall(Base):
|
||||
status: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||
elapsed_ms: Mapped[int] = mapped_column(Integer, nullable=False, default=0, server_default=text('0'))
|
||||
trace_id: Mapped[str] = mapped_column(String(64), nullable=False, default='', server_default='')
|
||||
# 线级事实(database 最终 SQL/绑定/行数;soap endpoint+XML;rest HTTP 往返)。
|
||||
# 可空:历史行与未捕获场景为 NULL,前台如实展示。
|
||||
wire_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
|
||||
# 通用业务锚点:调用方透传的业务单号/任务号(能力无关;不传为 NULL)。
|
||||
business_ref: Mapped[Optional[str]] = mapped_column(String(128), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
Reference in new issue
Block a user