Commit e85db902 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Refactor WAF service methods to use UUID instead of ID for attack log retrieval

- Update GetAttackLogDetails and GetAttackLogRsp methods in the WafController and wafService to accept UUID as a string parameter instead of a uint32 ID.
- Modify corresponding service interface to reflect the change in parameter type for improved clarity and consistency in handling attack logs.
parent 85023784
...@@ -375,14 +375,9 @@ func (c *WafController) GetAttackLogDetails(ctx *gin.Context) { ...@@ -375,14 +375,9 @@ func (c *WafController) GetAttackLogDetails(ctx *gin.Context) {
ctx1, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx1, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()
id := ctx.Query("uuid") uuid := ctx.Query("uuid")
idUint, err := strconv.ParseUint(id, 10, 32)
if err != nil {
utils.AssembleResponse(ctx, nil, err)
return
}
details, err := c.service.GetAttackLogDetails(ctx1, uint32(idUint)) details, err := c.service.GetAttackLogDetails(ctx1, uuid)
if err != nil { if err != nil {
utils.AssembleResponse(ctx, nil, err) utils.AssembleResponse(ctx, nil, err)
return return
...@@ -397,12 +392,8 @@ func (c *WafController) GetAttackLogRsp(ctx *gin.Context) { ...@@ -397,12 +392,8 @@ func (c *WafController) GetAttackLogRsp(ctx *gin.Context) {
ctx1, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx1, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()
id := ctx.Query("uuid") uuid := ctx.Query("uuid")
idUint, err := strconv.ParseUint(id, 10, 32)
if err != nil {
utils.AssembleResponse(ctx, nil, err)
return
}
length := ctx.Query("length") length := ctx.Query("length")
lengthUint, err := strconv.ParseUint(length, 10, 32) lengthUint, err := strconv.ParseUint(length, 10, 32)
if err != nil { if err != nil {
...@@ -410,7 +401,7 @@ func (c *WafController) GetAttackLogRsp(ctx *gin.Context) { ...@@ -410,7 +401,7 @@ func (c *WafController) GetAttackLogRsp(ctx *gin.Context) {
return return
} }
rsp, err := c.service.GetAttackLogRsp(ctx1, uint32(idUint), uint32(lengthUint)) rsp, err := c.service.GetAttackLogRsp(ctx1, uuid, uint32(lengthUint))
if err != nil { if err != nil {
utils.AssembleResponse(ctx, nil, err) utils.AssembleResponse(ctx, nil, err)
return return
......
...@@ -20,8 +20,8 @@ type Service interface { ...@@ -20,8 +20,8 @@ type Service interface {
DeleteListenerWaf(ctx context.Context, req *DeleteListenerReq) error DeleteListenerWaf(ctx context.Context, req *DeleteListenerReq) error
EnableListenerWafs(ctx context.Context, req *EnableListenerWafsReq) error EnableListenerWafs(ctx context.Context, req *EnableListenerWafsReq) error
ListAttackLogs(ctx context.Context, req *AttackLogFilter) ([]AttackLog, string, error) ListAttackLogs(ctx context.Context, req *AttackLogFilter) ([]AttackLog, string, error)
GetAttackLogDetails(ctx context.Context, id uint32) (*AttackLog, error) GetAttackLogDetails(ctx context.Context, uuid string) (*AttackLog, error)
GetAttackLogRsp(ctx context.Context, id uint32, length uint32) (*AttackRsp, error) GetAttackLogRsp(ctx context.Context, uuid string, length uint32) (*AttackRsp, error)
ListRules(ctx context.Context, regionCode, namespace, gatewayName, language, name string) ([]RuleGroupResp, error) ListRules(ctx context.Context, regionCode, namespace, gatewayName, language, name string) ([]RuleGroupResp, error)
CreateBlackWhiteList(ctx context.Context, req *MatcherExpr) error CreateBlackWhiteList(ctx context.Context, req *MatcherExpr) error
UpdateBlackWhiteList(ctx context.Context, req *MatcherExpr) error UpdateBlackWhiteList(ctx context.Context, req *MatcherExpr) error
......
...@@ -1004,9 +1004,9 @@ func (s *wafService) ListAttackLogs(ctx context.Context, req *AttackLogFilter) ( ...@@ -1004,9 +1004,9 @@ func (s *wafService) ListAttackLogs(ctx context.Context, req *AttackLogFilter) (
return attackLogs, pageToken, nil return attackLogs, pageToken, nil
} }
func (s *wafService) GetAttackLogDetails(ctx context.Context, id uint32) (*AttackLog, error) { func (s *wafService) GetAttackLogDetails(ctx context.Context, uuid string) (*AttackLog, error) {
res, err := s.elasticClient.Search("waf-detections*"). res, err := s.elasticClient.Search("waf-detections*").
Query(elastic.NewTermQuery("id.keyword", id)).Do(ctx) Query(elastic.NewTermQuery("id.keyword", uuid)).Do(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to search waf detections: %v", err) return nil, fmt.Errorf("failed to search waf detections: %v", err)
} }
...@@ -1030,9 +1030,9 @@ func (s *wafService) GetAttackLogDetails(ctx context.Context, id uint32) (*Attac ...@@ -1030,9 +1030,9 @@ func (s *wafService) GetAttackLogDetails(ctx context.Context, id uint32) (*Attac
return attackLog, nil return attackLog, nil
} }
func (s *wafService) GetAttackLogRsp(ctx context.Context, id uint32, length uint32) (*AttackRsp, error) { func (s *wafService) GetAttackLogRsp(ctx context.Context, uuid string, length uint32) (*AttackRsp, error) {
res, err := s.elasticClient.Search("waf-detections*"). res, err := s.elasticClient.Search("waf-detections*").
Query(elastic.NewTermQuery("id.keyword", id)).Do(ctx) Query(elastic.NewTermQuery("id.keyword", uuid)).Do(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to search waf detections: %v", err) return nil, fmt.Errorf("failed to search waf detections: %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