Commit 43bf5d54 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Enhance ListRules method to support localized filtering by name

- Modify the ListRules method in the WAF service to allow filtering of rule categories based on the specified language and name.
- Implement dynamic query construction to support localization for both Chinese and English categories.
parent 40a3f5ba
...@@ -933,7 +933,19 @@ func (s *wafService) ListAttackLogs(ctx context.Context, req *AttackLogFilter) ( ...@@ -933,7 +933,19 @@ func (s *wafService) ListAttackLogs(ctx context.Context, req *AttackLogFilter) (
func (s *wafService) ListRules(ctx context.Context, regionCode, namespace, gatewayName, language, name string) ([]RuleGroupResp, error) { func (s *wafService) ListRules(ctx context.Context, regionCode, namespace, gatewayName, language, name string) ([]RuleGroupResp, error) {
ruleCategories := []model.WafRuleCategory{} ruleCategories := []model.WafRuleCategory{}
err := s.db.Model(&model.WafRuleCategory{}).Find(&ruleCategories).Error db := s.db.Model(&model.WafRuleCategory{})
if name != "" {
col := "category_zh"
switch language {
case "zh":
col = "category_zh"
case "en":
col = "category_en"
}
like := fmt.Sprintf("%s LIKE ?", col)
db = db.Where(like, "%"+name+"%")
}
err := db.Find(&ruleCategories).Error
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get waf service: %v", err) return nil, fmt.Errorf("failed to get waf service: %v", err)
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment