Skip to content

Cb rule template#492

Merged
Jarvis1105 merged 3 commits intomainfrom
cb_rule_template
Jul 17, 2025
Merged

Cb rule template#492
Jarvis1105 merged 3 commits intomainfrom
cb_rule_template

Conversation

@iwanghc
Copy link
Copy Markdown
Collaborator

@iwanghc iwanghc commented Jul 17, 2025

User description

issue: #489

管理数据源时:

  1. 新增开启审核总控制
  2. 新增工作台审核规则模板配置
  3. 工作台sql审核逻辑调整和使用专属规则模板

Description

  • 增加SQL审核总控制逻辑

  • 更新SQL工作台审核模板字段读取

  • 添加空指针检查保护逻辑

  • 更新国际化消息配置


Changes diagram

flowchart LR
  A["新增审核总控制字段 AuditEnabled"]
  B["更新 SQLQueryConfig 模板字段传递"]
  C["添加空指针检查逻辑"]
  D["更新国际化语言配置"]
  A -- "同步字段" --> B
  B -- "增加检查" --> C
  C -- "调整消息" --> D
Loading

Changes walkthrough 📝

Relevant files
Enhancement
9 files
cloudbeaver.go
修改直接审计配置及空指针检查                                                                                     
+5/-2     
db_service.go
新增DBService审核配置逻辑                                                                               
+3/-1     
db_service.go
传递并设置审核开关及模板字段                                                                                     
+18/-0   
db_service_sync_task.go
同步任务中增加审核配置字段                                                                                       
+6/-0     
convert.go
转换数据服务支持审核相关字段                                                                                     
+26/-13 
model.go
模型中增加审核及模板字段定义                                                                                     
+3/-0     
message_zh.go
更新中文语言包审核相关消息                                                                                       
+62/-60 
active.en.toml
更新英文国际化审核模板消息                                                                                       
+2/-0     
active.zh.toml
更新中文国际化审核模板消息                                                                                       
+2/-0     

Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @github-actions
    Copy link
    Copy Markdown

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    添加空指针检查

    在构造 directAuditReq 时直接访问 dbService.SQLEConfig.SQLQueryConfig.RuleTemplateName 会存在
    nil 指针风险。建议先检查 dbService.SQLEConfigdbService.SQLEConfig.SQLQueryConfig 是否为
    nil,并为未初始化的情况设定合理的默认值,从而防止触发 panic。

    internal/dms/biz/cloudbeaver.go [458]

    -RuleTemplateName: dbService.SQLEConfig.SQLQueryConfig.RuleTemplateName,
    +var ruleTemplateName string
    +if dbService.SQLEConfig != nil && dbService.SQLEConfig.SQLQueryConfig != nil {
    +    ruleTemplateName = dbService.SQLEConfig.SQLQueryConfig.RuleTemplateName
    +} else {
    +    ruleTemplateName = ""
    +}
    +directAuditReq := cloudbeaver.DirectAuditParams{
    +    AuditSQLReq: cloudbeaver.AuditSQLReq{
    +        InstanceType:     dbService.DBType,
    +        ProjectId:        dbService.ProjectUID,
    +        RuleTemplateName: ruleTemplateName,
    +    },
    +    SQLEAddr:                         fmt.Sprintf("%s/v2/sql_audit", sqleUrl),
    +    AllowQueryWhenLessThanAuditLevel: dbService.GetAllowQueryWhenLessThanAuditLevel(),
    +}
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion addresses a potential nil pointer dereference by adding checks for dbService.SQLEConfig and dbService.SQLEConfig.SQLQueryConfig, which is crucial to prevent run-time panics while handling the directAuditReq.

    Medium

    @Jarvis1105 Jarvis1105 merged commit feaa2c2 into main Jul 17, 2025
    1 check passed
    @Jarvis1105 Jarvis1105 deleted the cb_rule_template branch July 17, 2025 06:46
    LordofAvernus pushed a commit that referenced this pull request Apr 9, 2026
    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.

    2 participants