You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (sqlWorkbenchService *SqlWorkbenchService) buildAuditResponseWithoutExecution(c echo.Context, userId string, auditResult *cloudbeaver.AuditSQLReply, dbService *biz.DBService) error {
+ // 检查 auditResult.Data 是否为 nil,防止 nil 指针异常+ if auditResult.Data == nil {+ return fmt.Errorf("audit result data is nil")+ }
// 构造 SQL 条目列表
sqlItems := make([]StreamExecuteSQLItem, 0, len(auditResult.Data.SQLResults))
for _, sqlResult := range auditResult.Data.SQLResults {
// 转换审核结果为 violatedRules 格式
violatedRules := sqlWorkbenchService.convertSQLEAuditToViolatedRules(&sqlResult)
...
}
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly adds a defensive check for nil on auditResult.Data to avoid potential panic when dereferencing, which is important for robustness. It directly addresses a possible runtime error in the buildAuditResponseWithoutExecution function.
func (sqlWorkbenchService *SqlWorkbenchService) mapAuditLevelToNumber(level string) int {
switch strings.ToLower(level) {
case "normal":
return 0
case "notice":
+ return 1+ case "warn":+ return 2+ case "error":
return 3
- case "warn":- return 1- case "error":- return 2
default:
- return 0 // 默认为 notice+ return 1 // 默认为 notice
}
}
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a mismatch in the mapping logic of mapAuditLevelToNumber, aligning the return values with the documented mapping (normal=0, notice=1, warn=2, error=3), which is crucial for proper audit logic.
Why: The suggestion improves error handling by returning an error response instead of proceeding with next(c), which could prevent bypassing audit checks; however, this change might alter the intended middleware flow.
-normalizedSQL := strings.TrimSpace(strings.TrimSuffix(sqlItem.SQLTuple.OriginalSQL, ";"))+normalizedSQL := strings.ToLower(strings.TrimSpace(strings.TrimSuffix(sqlItem.SQLTuple.OriginalSQL, ";")))
if auditResult, found := sqlAuditMap[normalizedSQL]; found {
matchedAuditResult = auditResult
}
Suggestion importance[1-10]: 5
__
Why: Adding a conversion to lower case enhances consistency in SQL matching, reducing potential mismatches due to case differences; the improvement is correct but has only a minor impact.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
关联的 issue
actiontech/sqle#3133
描述你的变更
确认项(pr提交后操作)
Tip
请在指定复审人之前,确认并完成以下事项,完成后✅
not_compatibleneed_update_docDescription
为 SQL 工作台新增审核中间件
扩展 streamExecute 请求及 sid 解析
集成 SQLE 审核接口及审批逻辑
增加操作日志记录与响应拦截
Diagram Walkthrough
File Walkthrough
router.go
调用审核中间件internal/apiserver/service/router.go
model.go
增加审核结果消息字段internal/dms/storage/model/model.go
graphql.go
修改审核响应类型名称internal/pkg/cloudbeaver/graphql.go
sql_workbench_service.go
增加审核中间件及审批日志功能internal/sql_workbench/service/sql_workbench_service.go