Commit 64b675ef authored by qiuqunfeng's avatar qiuqunfeng
Browse files

commit

parent 3ce3ff4a
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/rs/zerolog/log"
"gitlab.com/tensorsecurity-rd/waf-console/internal/model" "gitlab.com/tensorsecurity-rd/waf-console/internal/model"
"gitlab.com/tensorsecurity-rd/waf-console/internal/utils" "gitlab.com/tensorsecurity-rd/waf-console/internal/utils"
"gitlab.com/tensorsecurity-rd/waf-console/pkg/apis/waf.security.io/v1alpha1" "gitlab.com/tensorsecurity-rd/waf-console/pkg/apis/waf.security.io/v1alpha1"
...@@ -405,11 +406,25 @@ func (s *wafService) EnableListenerWaf(ctx context.Context, req *EnableListenerW ...@@ -405,11 +406,25 @@ func (s *wafService) EnableListenerWaf(ctx context.Context, req *EnableListenerW
wafService := &model.WafService{} wafService := &model.WafService{}
err = s.db.Model(&model.WafService{}).Where("gateway_name = ? AND namespace = ? AND region_code = ?", req.GatewayName, req.Namespace, req.RegionCode).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 && err != gorm.ErrRecordNotFound { if err != nil {
if err == gorm.ErrRecordNotFound {
wafService = &model.WafService{
GatewayName: req.GatewayName,
Namespace: req.Namespace,
RegionCode: req.RegionCode,
Mode: string(WafModeAlert),
Host: model.HostList([]string{"*"}),
}
if err := s.db.Create(wafService).Error; err != nil {
return err
}
} else {
return err return err
} }
}
if listener.Enable { if listener.Enable {
log.Info().Msgf("Create WAF for listener %s", listener.GatewayName)
_, err := s.CreateWaf(ctx, &CreateWafReq{ _, err := s.CreateWaf(ctx, &CreateWafReq{
GatewateInfo: GatewateInfo{ GatewateInfo: GatewateInfo{
GatewayName: req.GatewayName, GatewayName: req.GatewayName,
...@@ -423,6 +438,7 @@ func (s *wafService) EnableListenerWaf(ctx context.Context, req *EnableListenerW ...@@ -423,6 +438,7 @@ func (s *wafService) EnableListenerWaf(ctx context.Context, req *EnableListenerW
return err return err
} }
} else { } else {
log.Info().Msgf("Delete WAF for listener %s", listener.GatewayName)
err = s.DeleteListenerWaf(ctx, &DeleteListenerReq{ err = s.DeleteListenerWaf(ctx, &DeleteListenerReq{
GatewateInfo: GatewateInfo{ GatewateInfo: GatewateInfo{
GatewayName: req.GatewayName, GatewayName: req.GatewayName,
......
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