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

commit

parent 3ce3ff4a
......@@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"github.com/rs/zerolog/log"
"gitlab.com/tensorsecurity-rd/waf-console/internal/model"
"gitlab.com/tensorsecurity-rd/waf-console/internal/utils"
"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
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
if err != nil && err != gorm.ErrRecordNotFound {
return err
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
}
}
if listener.Enable {
log.Info().Msgf("Create WAF for listener %s", listener.GatewayName)
_, err := s.CreateWaf(ctx, &CreateWafReq{
GatewateInfo: GatewateInfo{
GatewayName: req.GatewayName,
......@@ -423,6 +438,7 @@ func (s *wafService) EnableListenerWaf(ctx context.Context, req *EnableListenerW
return err
}
} else {
log.Info().Msgf("Delete WAF for listener %s", listener.GatewayName)
err = s.DeleteListenerWaf(ctx, &DeleteListenerReq{
GatewateInfo: GatewateInfo{
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