feat: 添加飞书集成和改进安全配置 - 集成 lark-oapi 库以支持飞书功能 - 改进 CORS 配置验证器以支持 JSON 格式输入 - 添加安全凭证检查逻辑以防止跨域安全问题 - 在 DirectLLMAdapter 中增加响应解析异常处理 fix: 增强查询参数验证和分页限制 - 为多个路由添加 Query 参数验证器 - 实现 bounded_limit 和 bounded_offset 辅助函数 - 设置查询限制范围为 1-500 之间 - 使用 secrets.compare_digest 提升令牌验证安全性 refactor: 调整文档忽略规则和测试配置 - 更新 .gitignore 文件中的文档路径配置 - 在 smoke 测试中添加必要的环境变量配置 - 重构配置验证器以提高类型兼容性 ```
62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.database import get_db
|
|
from app.core.security import ApiPrincipal, require_api_key
|
|
from app.modules.legacy_mysql.schemas import (
|
|
LegacyProjectSyncRequest,
|
|
LegacyProjectSyncResult,
|
|
QueryResult,
|
|
ReadonlyQueryRequest,
|
|
)
|
|
from app.modules.legacy_mysql.service import LegacyMySQLService
|
|
|
|
router = APIRouter(dependencies=[Depends(require_api_key)])
|
|
|
|
|
|
@router.get("/health")
|
|
def mysql_health(db: Session = Depends(get_db)) -> dict[str, str]:
|
|
return LegacyMySQLService(db).health()
|
|
|
|
|
|
@router.get("/tables")
|
|
def list_tables(db: Session = Depends(get_db)) -> dict[str, list[str]]:
|
|
return {"tables": LegacyMySQLService(db).list_tables()}
|
|
|
|
|
|
@router.get("/tables/{table_name}")
|
|
def describe_table(table_name: str, db: Session = Depends(get_db)) -> dict:
|
|
return {"table": table_name, "columns": LegacyMySQLService(db).describe_table(table_name)}
|
|
|
|
|
|
@router.post("/query", response_model=QueryResult)
|
|
def readonly_query(payload: ReadonlyQueryRequest, db: Session = Depends(get_db)) -> dict:
|
|
service = LegacyMySQLService(db)
|
|
if payload.sql:
|
|
return service.execute_readonly(payload.sql, payload.params, payload.limit)
|
|
return service.execute_allowed_query(payload.query_name, payload.params, payload.limit)
|
|
|
|
|
|
@router.get("/projects", response_model=QueryResult)
|
|
def default_project_query(
|
|
limit: int = Query(default=100, ge=1, le=500),
|
|
db: Session = Depends(get_db),
|
|
) -> dict:
|
|
return LegacyMySQLService(db).fetch_default_projects(limit=limit)
|
|
|
|
|
|
@router.post("/projects/sync", response_model=LegacyProjectSyncResult)
|
|
def sync_projects(
|
|
payload: LegacyProjectSyncRequest,
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
return LegacyMySQLService(db).sync_projects(
|
|
source_query=payload.source_query,
|
|
source_query_name=payload.source_query_name,
|
|
field_map=payload.field_map,
|
|
limit=payload.limit,
|
|
dry_run=payload.dry_run,
|
|
actor=principal.actor,
|
|
)
|