Commit 2964b4c2 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

commit

parent 1fd0a160
...@@ -26,7 +26,9 @@ func (c *WafController) Waf(ctx *gin.Context) { ...@@ -26,7 +26,9 @@ func (c *WafController) Waf(ctx *gin.Context) {
defer cancel() defer cancel()
gatewayName := ctx.Param("gateway_name") gatewayName := ctx.Param("gateway_name")
waf, err := c.service.GetWaf(ctx1, gatewayName) regionCode := ctx.Param("region_code")
namespace := ctx.Param("namespace")
waf, err := c.service.GetWaf(ctx1, regionCode, namespace, gatewayName)
if err != nil { if err != nil {
// logging.Get().Err(err).Msgf("get waf") // logging.Get().Err(err).Msgf("get waf")
utils.AssembleResponse(ctx, nil, err) utils.AssembleResponse(ctx, nil, err)
......
...@@ -4,7 +4,7 @@ import "context" ...@@ -4,7 +4,7 @@ import "context"
type Service interface { type Service interface {
// QueryIP(ip string) (*model.IPInfo, error) // QueryIP(ip string) (*model.IPInfo, error)
GetWaf(ctx context.Context, gatewayName string) (*WafService, error) GetWaf(ctx context.Context, regionCode, namespace, gatewayName string) (*WafService, error)
CreateWaf(ctx context.Context, req *CreateWafReq) (*WafService, error) CreateWaf(ctx context.Context, req *CreateWafReq) (*WafService, error)
UpdateMode(ctx context.Context, req *UpdateModeReq) (*WafService, error) UpdateMode(ctx context.Context, req *UpdateModeReq) (*WafService, error)
SaveRuleCategoryToDB(ctx context.Context) error SaveRuleCategoryToDB(ctx context.Context) error
......
...@@ -23,13 +23,15 @@ func NewWafService(client *versioned.Clientset, db *gorm.DB) Service { ...@@ -23,13 +23,15 @@ func NewWafService(client *versioned.Clientset, db *gorm.DB) Service {
return &wafService{client: client, db: db} return &wafService{client: client, db: db}
} }
func (s *wafService) GetWaf(ctx context.Context, gatewayName string) (*WafService, error) { func (s *wafService) GetWaf(ctx context.Context, regionCode, namespace, gatewayName string) (*WafService, error) {
wafService := &model.WafService{} wafService := &model.WafService{}
err := s.db.Model(&model.WafService{}).Where("gateway_name = ?", gatewayName).First(wafService).Error err := s.db.Model(&model.WafService{}).Where("gateway_name = ? AND region_code = ? AND namespace = ?", gatewayName, regionCode, namespace).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
wafService = &model.WafService{ wafService = &model.WafService{
RegionCode: regionCode,
Namespace: namespace,
GatewayName: gatewayName, GatewayName: gatewayName,
Mode: string(WafModeAlert), Mode: string(WafModeAlert),
} }
...@@ -88,6 +90,8 @@ func (s *wafService) CreateWaf(ctx context.Context, req *CreateWafReq) (*WafServ ...@@ -88,6 +90,8 @@ func (s *wafService) CreateWaf(ctx context.Context, req *CreateWafReq) (*WafServ
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
// Create new WAF service record if not found // Create new WAF service record if not found
wafService = &model.WafService{ wafService = &model.WafService{
RegionCode: req.RegionCode,
Namespace: req.Namespace,
GatewayName: req.GatewayName, GatewayName: req.GatewayName,
Mode: string(WafModeAlert), Mode: string(WafModeAlert),
} }
...@@ -145,6 +149,8 @@ func (s *wafService) UpdateMode(ctx context.Context, req *UpdateModeReq) (*WafSe ...@@ -145,6 +149,8 @@ func (s *wafService) UpdateMode(ctx context.Context, req *UpdateModeReq) (*WafSe
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
// Create new WAF service record if not found // Create new WAF service record if not found
wafService = &model.WafService{ wafService = &model.WafService{
RegionCode: req.RegionCode,
Namespace: req.Namespace,
GatewayName: req.GatewayName, GatewayName: req.GatewayName,
Mode: string(req.Mode), Mode: string(req.Mode),
} }
......
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