Commit 56ce2571 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Refactor WAF service listener deletion logic to include namespace and region...

Refactor WAF service listener deletion logic to include namespace and region code in the query, enhancing specificity and accuracy in service management. Additionally, remove redundant action check in WAF detection generation to simplify error handling.
parent 4835dac7
...@@ -137,9 +137,7 @@ func (s *LogConsumerService) genWafDetection(wafDetectionMessage model.WafDetect ...@@ -137,9 +137,7 @@ func (s *LogConsumerService) genWafDetection(wafDetectionMessage model.WafDetect
if attackedLog.AttackIP == "" { if attackedLog.AttackIP == "" {
return model.WafDetection{}, errors.New("attack_ip is empty") return model.WafDetection{}, errors.New("attack_ip is empty")
} }
if attackedLog.Action != "pass" {
return model.WafDetection{}, errors.New("action is not pass")
}
wafDetection := model.WafDetection{ wafDetection := model.WafDetection{
WafDetectionMessageBasic: wafDetectionMessage.WafDetectionMessageBasic, WafDetectionMessageBasic: wafDetectionMessage.WafDetectionMessageBasic,
WafDetectionAttackedLog: attackedLog, WafDetectionAttackedLog: attackedLog,
......
...@@ -385,7 +385,7 @@ func (s *wafService) DeleteListenerWaf(ctx context.Context, req *DeleteListenerR ...@@ -385,7 +385,7 @@ func (s *wafService) DeleteListenerWaf(ctx context.Context, req *DeleteListenerR
func (s *wafService) UpdateMode(ctx context.Context, req *UpdateModeReq) (*WafService, error) { func (s *wafService) UpdateMode(ctx context.Context, req *UpdateModeReq) (*WafService, error) {
// Check if WAF service exists // Check if WAF service exists
wafService := &model.WafService{} wafService := &model.WafService{}
err := s.db.Model(&model.WafService{}).Where("gateway_name = ?", req.GatewayName).First(wafService).Error err := s.db.Model(&model.WafService{}).Where("gateway_name = ? and namespace = ? and region_code = ?", req.GatewayName, req.Namespace, req.RegionCode).First(wafService).Error
if err != nil { if err != nil {
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
// Create new WAF service record if not found // Create new WAF service record if not found
......
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