Skip to content

feat: SQL 单规则例外(标准 CE)#3339

Open
LordofAvernus wants to merge 1 commit into
mainfrom
dev/rule-exc
Open

feat: SQL 单规则例外(标准 CE)#3339
LordofAvernus wants to merge 1 commit into
mainfrom
dev/rule-exc

Conversation

@LordofAvernus

@LordofAvernus LordofAvernus commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

User description

变更说明

  • 交付角色:标准 CE
  • 源分支:dev/rule-exc
  • 目标分支:main
  • 覆盖 AC-SQL-RULE-EXC-001 至 AC-SQL-RULE-EXC-024

关联 Issue: https://github.com/actiontech/sqle-ee/issues/2991


Description

  • 新增 SQL 单规则例外增删功能

  • 实现 SQLRuleException 数据模型

  • 扩展审计、操作记录接口

  • 更新单元测试及 API 文档


Diagram Walkthrough

flowchart LR
  A["新增 SQL 单规则例外"] --> B["新增数据库模型"]
  A --> C["新增接口逻辑"]
  A --> D["更新测试和文档"]
Loading

File Walkthrough

Relevant files
Enhancement
13 files
operation_record_rule_exception.go
添加 SQL 单规则例外接口和业务逻辑                                                                           
+516/-0 
sql_whitelist.go
扩展审计白名单接口支持例外功能                                                                                   
+230/-0 
sql_rule_exception.go
新增 SQLRuleException 数据模型及操作函数                                                       
+245/-0 
operation_record_query.go
新增操作记录查询模板和统计接口                                                                                   
+161/-0 
operation_record.go
扩展操作记录接口,记录详细操作内容                                                                               
+133/-0 
audit.go
修改审计流程,增加跳过例外规则校验                                                                               
+75/-0   
task.go
更新任务模型支持跳过审核结果记录                                                                                 
+19/-17 
operation_record_ce.go
扩展中间件记录操作日志细节                                                                                       
+96/-3   
app.go
注册新的 SQL 例外接口路由及处理函数                                                                         
+9/-0     
sql_audit.go
修改审核接口输出,包含跳过规则结果                                                                               
+18/-15 
operation_record.go
更新操作记录模型,完善日志字段                                                                                   
+32/-14 
task.go
修改任务接口返回结构加入跳过结果                                                                                 
+13/-0   
utils.go
更新自动迁移列表注册 SQLRuleException 模型                                                     
+1/-0     
Tests
3 files
sql_rule_exception_test.go
添加单规则例外单元测试用例                                                                                       
+219/-0 
audit_degrade_test.go
添加与优化 SQL 审核例外测试逻辑                                                                             
+147/-0 
sql_audit_test.go
添加测试覆盖跳过审核例外逻辑                                                                                     
+36/-0   
Documentation
2 files
docs.go
更新 API 文档,增加 SQL 例外接口说明                                                                   
+287/-0 
swagger.yaml
更新 Swagger 定义,增加 SQL 例外接口说明                                                           
+192/-0 
Additional files
1 files
swagger.json +287/-0 

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

🎫 Ticket compliance analysis 🔶

2991 - Partially compliant

Compliant requirements:

Non-compliant requirements:

  • 未实现韩文语言包国际化支持功能

Requires further human verification:

⏱️ Estimated effort to review: 5 🔵🔵🔵🔵🔵
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

错误处理

函数 GetEffectiveSQLRuleException 在数据库查询成功时依然通过 errors.New() 包装返回错误,这可能导致调用者误判查询失败。建议在 err 为 nil 时直接返回 nil。

func (s *Storage) GetEffectiveSQLRuleException(projectID ProjectUID, instanceID uint64, sqlFingerprint, ruleName string) (*SQLRuleException, bool, error) {
	sqlRuleException := &SQLRuleException{}
	err := s.db.Where("project_id = ? AND instance_id = ? AND sql_fingerprint = ? AND rule_name = ?", projectID, instanceID, strings.TrimSpace(sqlFingerprint), strings.TrimSpace(ruleName)).
		First(sqlRuleException).Error
	if err == gorm.ErrRecordNotFound {
		return nil, false, nil
	}
	return sqlRuleException, true, errors.New(errors.ConnectStorageError, err)

@github-actions

Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
统一ID字段类型

建议将路径参数 sql_rule_exception_id 的数据类型从字符串改为整数,以与响应体中定义的类型保持一致,防止因类型不匹配导致的潜在错误。

sqle/docs/swagger.json [2863-2869]

 {
-    "type": "string",
+    "type": "integer",
     "description": "sql rule exception id",
     "name": "sql_rule_exception_id",
     "in": "path",
     "required": true
 }
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly points out the inconsistency in the sql_rule_exception_id type and proposes changing it from a string to an integer to match the response schema. Its impact is moderate as it improves API consistency.

Medium

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant