mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-05 13:27:55 +08:00
✨ feat(sql-audit): 新增 SQL 审计中心并完善事务追踪
- 新增脱敏审计存储、筛选、保留策略、完整性校验与 JSON/CSV 导出 - 覆盖查询编辑器、事务、导入同步、对象操作、AI/MCP 与 Web 运行时入口 - 完善事务完整语句日志、Windows 快捷键映射及 SQL 分析布局 - 补充多语言、健康状态、数据目录迁移和回归测试
This commit is contained in:
@@ -26,14 +26,15 @@ type Backend interface {
|
||||
DBGetForeignKeys(config connection.ConnectionConfig, dbName string, tableName string) connection.QueryResult
|
||||
DBGetTriggers(config connection.ConnectionConfig, dbName string, tableName string) connection.QueryResult
|
||||
DBShowCreateTable(config connection.ConnectionConfig, dbName string, tableName string) connection.QueryResult
|
||||
DBQueryMulti(config connection.ConnectionConfig, dbName string, query string, queryID string) connection.QueryResult
|
||||
ExecuteSQLFromMCP(config connection.ConnectionConfig, dbName string, query string) connection.QueryResult
|
||||
InspectSQL(dbType string, sql string) appcore.SQLInspection
|
||||
GetSQLSafetyLevel() ai.SQLPermissionLevel
|
||||
}
|
||||
|
||||
// AppBackend 基于现有 internal/app.App 暴露 MCP 所需数据库能力。
|
||||
type AppBackend struct {
|
||||
app *appcore.App
|
||||
app *appcore.App
|
||||
mcpQueryExecutor *appcore.MCPQueryExecutor
|
||||
}
|
||||
|
||||
func NewAppBackend(ctx context.Context) *AppBackend {
|
||||
@@ -42,7 +43,7 @@ func NewAppBackend(ctx context.Context) *AppBackend {
|
||||
}
|
||||
a := appcore.NewApp()
|
||||
appcore.InitializeLifecycle(a, ctx)
|
||||
return &AppBackend{app: a}
|
||||
return &AppBackend{app: a, mcpQueryExecutor: appcore.NewMCPQueryExecutor(a)}
|
||||
}
|
||||
|
||||
func (b *AppBackend) Close(ctx context.Context) error {
|
||||
@@ -101,8 +102,8 @@ func (b *AppBackend) DBShowCreateTable(config connection.ConnectionConfig, dbNam
|
||||
return b.app.DBShowCreateTable(config, dbName, tableName)
|
||||
}
|
||||
|
||||
func (b *AppBackend) DBQueryMulti(config connection.ConnectionConfig, dbName string, query string, queryID string) connection.QueryResult {
|
||||
return b.app.DBQueryMulti(config, dbName, query, queryID)
|
||||
func (b *AppBackend) ExecuteSQLFromMCP(config connection.ConnectionConfig, dbName string, query string) connection.QueryResult {
|
||||
return b.mcpQueryExecutor.DBQueryMulti(config, dbName, query)
|
||||
}
|
||||
|
||||
func (b *AppBackend) InspectSQL(dbType string, sql string) appcore.SQLInspection {
|
||||
|
||||
@@ -546,7 +546,7 @@ func (s *Service) ExecuteSQL(ctx context.Context, req *mcp.CallToolRequest, args
|
||||
}
|
||||
|
||||
dbName := effectiveDBName(args.DBName, view.Config)
|
||||
queryResult := s.backend.DBQueryMulti(view.Config, dbName, sqlText, "")
|
||||
queryResult := s.backend.ExecuteSQLFromMCP(view.Config, dbName, sqlText)
|
||||
if !queryResult.Success {
|
||||
return toolError("SQL 执行失败: %s", strings.TrimSpace(queryResult.Message)), executeSQLResult{}, nil
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func (f *fakeBackend) DBShowCreateTable(config connection.ConnectionConfig, dbNa
|
||||
return f.ddlResult
|
||||
}
|
||||
|
||||
func (f *fakeBackend) DBQueryMulti(config connection.ConnectionConfig, dbName string, query string, queryID string) connection.QueryResult {
|
||||
func (f *fakeBackend) ExecuteSQLFromMCP(config connection.ConnectionConfig, dbName string, query string) connection.QueryResult {
|
||||
f.queryCalled = true
|
||||
return f.queryResult
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user