Commit 1c461f5a authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Add getScopeName function to retrieve gateway names from WAF services and...

Add getScopeName function to retrieve gateway names from WAF services and integrate it into GetBlackWhiteLists response

This new function fetches gateway names based on the provided scope and enhances the GetBlackWhiteLists method by including the ScopeName field in the response. This change improves data representation and clarity in WAF listings.
parent 6493a88a
......@@ -1441,6 +1441,19 @@ func GetLikeExpr(s string) string {
return sb.String()
}
func getScopeName(ctx context.Context, db *gorm.DB, scope []uint32) ([]string, error) {
var results []model.WafService
err := db.WithContext(ctx).Raw("select gateway_name from waf_services where id in ? ", scope).Scan(&results).Error
if err != nil {
return nil, err
}
names := []string{}
for _, r := range results {
names = append(names, r.GatewayName)
}
return names, nil
}
func (s *wafService) GetBlackWhiteLists(ctx context.Context, query *MatchExprQueryOption, limit int, offset int) ([]MatcherExpr, int, error) {
oneCtx, oneCancel := context.WithTimeout(ctx, 750*time.Millisecond)
defer oneCancel()
......@@ -1472,14 +1485,19 @@ func (s *wafService) GetBlackWhiteLists(ctx context.Context, query *MatchExprQue
}
exprsResp := []MatcherExpr{}
for _, expr := range exprs {
scopeNames, err := getScopeName(ctx, s.db, expr.Scope)
if err != nil {
return nil, 0, err
}
exprsResp = append(exprsResp, MatcherExpr{
ID: expr.ID,
Name: expr.Name,
Scope: expr.Scope,
Mode: expr.Mode,
Expr: expr.Expr,
Status: int32(expr.Status),
Global: expr.Global,
ID: expr.ID,
Name: expr.Name,
Scope: expr.Scope,
ScopeName: scopeNames,
Mode: expr.Mode,
Expr: expr.Expr,
Status: int32(expr.Status),
Global: expr.Global,
})
}
return exprsResp, int(total), nil
......
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