```
feat: 添加飞书集成和审计API密钥认证 - 在数据库配置中添加飞书模型导入 - 添加审计API密钥配置项和认证中间件 - 实现飞书事件重复处理防止机制 - 为审批路由添加API密钥认证 - 优化AI适配器错误处理并添加JSON解析异常捕获 - 更新测试用例以包含新的认证和事件处理逻辑 ```
This commit is contained in:
@@ -53,3 +53,25 @@ def require_approval_api_key(
|
||||
detail="Invalid approval API key",
|
||||
)
|
||||
return ApiPrincipal(actor=settings.approval_api_actor)
|
||||
|
||||
|
||||
def require_audit_api_key(
|
||||
x_audit_api_key: str | None = Header(
|
||||
default=None,
|
||||
alias=HttpHeader.X_AUDIT_API_KEY,
|
||||
),
|
||||
) -> ApiPrincipal:
|
||||
"""Validate the audit API key and return the audit principal."""
|
||||
|
||||
settings = get_settings()
|
||||
if not settings.audit_api_key:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||
detail="AUDIT_API_KEY is required",
|
||||
)
|
||||
if not x_audit_api_key or not compare_digest(x_audit_api_key, settings.audit_api_key):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Invalid audit API key",
|
||||
)
|
||||
return ApiPrincipal(actor=settings.audit_api_actor)
|
||||
|
||||
Reference in New Issue
Block a user