Skip to content

feat(data_masking): 支持自定义脱敏规则 - CE桩函数与API定义#605

Open
LordofAvernus wants to merge 1 commit intomainfrom
dms/feat-800
Open

feat(data_masking): 支持自定义脱敏规则 - CE桩函数与API定义#605
LordofAvernus wants to merge 1 commit intomainfrom
dms/feat-800

Conversation

@LordofAvernus
Copy link
Copy Markdown
Collaborator

@LordofAvernus LordofAvernus commented Apr 30, 2026

User description

Summary

  • 新增自定义脱敏规则相关API接口定义(masking.go),支持分页/筛选/搜索
  • 新增CE桩函数:规则CRUD、敏感类型管理、脱敏效果预览、数据库/表粒度扫描等
  • 更新data_export_workflow支持maskingRuleRepo依赖注入
  • 更新swagger文档

关联 EE Issue: https://github.com/actiontech/dms-ee/issues/800


Description

  • 新增项目级脱敏规则 API 定义

  • 添加敏感数据类型管理接口

  • 更新 swagger 文档说明与注释

  • 依赖注入中加入 maskingRuleRepo 支持


Diagram Walkthrough

flowchart LR
  A["更新API路径及请求参数"] --> B["新增脱敏规则及敏感类型API"]
  B --> C["添加CE桩函数支持"]
  C --> D["注入maskingRuleRepo依赖"]
Loading

File Walkthrough

Relevant files
Enhancement
6 files
data_mask_controller.go`
更新API接口路径及请求参数                                                                                     
masking.go`
新增脱敏规则及敏感数据类型 API 定义                                                                         
data_masking_ce.go`
添加CE桩函数支持脱敏规则接口                                                                                   
data_export_workflow.go`
注入新的 maskingRuleRepo 依赖                                                                   
service.go`
新增 maskingRuleRepo 初始化逻辑                                                                 
data_mask_ce.go`
定义 DataExportMaskingRuleRepo 接口                                                   
Additional files
8 files
masking.go +609/-20
swagger.json +1485/-281
swagger.yaml +1049/-120
data_mask_controller.go +564/-98
data_export_workflow.go +3/-1     
data_mask_ce.go +2/-0     
data_masking_ce.go +53/-1   
service.go +2/-1     

- 新增自定义脱敏规则相关API接口定义(masking.go)
- 更新ListMaskingRules接口支持分页/筛选/搜索参数
- 新增CE桩函数:规则CRUD、敏感类型管理、脱敏效果预览等
- 更新data_export_workflow支持maskingRuleRepo依赖注入
- 更新swagger文档
@actiontech-bot actiontech-bot requested a review from iwanghc April 30, 2026 09:16
@github-actions
Copy link
Copy Markdown

PR Reviewer Guide 🔍

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

代码复用

在新增的 AddMaskingTemplate 与 UpdateMaskingTemplate 中分别实现了 NormalizeRuleIDs 方法;这两处逻辑重复,建议提取公共函数以减少代码冗余,便于后续维护和保证逻辑一致性。

// NormalizeRuleIDs populates RuleIDs from RuleRefs if RuleIDs is empty.
// Returns an error if neither RuleIDs nor RuleRefs is provided.
func (t *AddMaskingTemplate) NormalizeRuleIDs() error {
	if len(t.RuleIDs) == 0 && len(t.RuleRefs) > 0 {
		t.RuleIDs = make([]int, 0, len(t.RuleRefs))
		for _, ref := range t.RuleRefs {
			t.RuleIDs = append(t.RuleIDs, ref.RuleID)
		}
	}
	if len(t.RuleIDs) == 0 {
		return fmt.Errorf("rule_ids or rule_refs is required and must not be empty")
	}
	return nil
}

// swagger:model AddMaskingTemplateReply
type AddMaskingTemplateReply struct {
	base.GenericResp
}

// swagger:model UpdateMaskingTemplateReq
type UpdateMaskingTemplateReq struct {
	// project uid
	// in: path
	// swagger:ignore
	// Required: true
	// Example: "project_uid"
	ProjectUid string `param:"project_uid" json:"project_uid" validate:"required"`
	// masking template id
	// in: path
	// swagger:ignore
	// Required: true
	// Example: 1
	TemplateID int `param:"template_id" json:"template_id" validate:"required"`
	// masking template
	// Required: true
	MaskingTemplate *UpdateMaskingTemplate `json:"masking_template" validate:"required"`
}

// swagger:model UpdateMaskingTemplate
type UpdateMaskingTemplate struct {
	// masking rule id list (deprecated, use rule_refs instead)
	// Example: [1, 2]
	RuleIDs []int `json:"rule_ids"`
	// masking rule references with source info
	// Example: [{"rule_id": 1, "rule_source": "builtin"}]
	RuleRefs []MaskingTemplateRuleRef `json:"rule_refs"`
}

// NormalizeRuleIDs populates RuleIDs from RuleRefs if RuleIDs is empty.
// Returns an error if neither RuleIDs nor RuleRefs is provided.
func (t *UpdateMaskingTemplate) NormalizeRuleIDs() error {
	if len(t.RuleIDs) == 0 && len(t.RuleRefs) > 0 {
		t.RuleIDs = make([]int, 0, len(t.RuleRefs))
		for _, ref := range t.RuleRefs {
			t.RuleIDs = append(t.RuleIDs, ref.RuleID)
		}
	}
	if len(t.RuleIDs) == 0 {
		return fmt.Errorf("rule_ids or rule_refs is required and must not be empty")
	}
	return nil

@github-actions
Copy link
Copy Markdown

Failed to generate code suggestions for PR

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