Commit bb958705 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Add WAF mode to CreateWaf and EnableListenerWaf requests

- Extend CreateWafReq and EnableListenerWafReq structs with Mode field
- Update CreateWaf method to use requested WAF mode
- Modify EnableListenerWafs to retrieve and apply WAF mode from existing service
- Ensure mode is consistently passed through WAF service operations
parent a1ed13b0
...@@ -188,6 +188,7 @@ type CreateWafReq struct { ...@@ -188,6 +188,7 @@ type CreateWafReq struct {
GatewateInfo GatewateInfo
Port uint32 `json:"port"` Port uint32 `json:"port"`
Host []string `json:"host"` Host []string `json:"host"`
Mode WafMode `json:"mode"`
} }
type DeleteWafReq struct { type DeleteWafReq struct {
...@@ -221,6 +222,7 @@ type EnableListenerWafReq struct { ...@@ -221,6 +222,7 @@ type EnableListenerWafReq struct {
Enable bool `json:"enable"` Enable bool `json:"enable"`
Hosts []string `json:"hosts"` Hosts []string `json:"hosts"`
Port int `json:"port"` Port int `json:"port"`
Mode WafMode `json:"mode"`
} }
type EnableGatewayWafReq struct { type EnableGatewayWafReq struct {
......
...@@ -213,7 +213,7 @@ func (s *wafService) CreateWaf(ctx context.Context, req *CreateWafReq) (*WafServ ...@@ -213,7 +213,7 @@ func (s *wafService) CreateWaf(ctx context.Context, req *CreateWafReq) (*WafServ
Enable: 1, Enable: 1,
Level: "info", Level: "info",
}, },
Mode: "block", Mode: string(req.Mode),
}, },
} }
...@@ -436,6 +436,7 @@ func (s *wafService) EnableListenerWaf(ctx context.Context, req *EnableListenerW ...@@ -436,6 +436,7 @@ func (s *wafService) EnableListenerWaf(ctx context.Context, req *EnableListenerW
}, },
Port: uint32(req.Port), Port: uint32(req.Port),
Host: req.Hosts, Host: req.Hosts,
Mode: req.Mode,
}) })
if err != nil { if err != nil {
return err return err
...@@ -676,6 +677,18 @@ func (s *wafService) EnableListenerWafs(ctx context.Context, req *EnableListener ...@@ -676,6 +677,18 @@ func (s *wafService) EnableListenerWafs(ctx context.Context, req *EnableListener
// enable WAF for ports that are in the desired port set but not in the current port set // enable WAF for ports that are in the desired port set but not in the current port set
addingPortSet := desiredPortSet.Difference(currentPortSet) addingPortSet := desiredPortSet.Difference(currentPortSet)
// Get mode from waf_services table
wafService := &model.WafService{}
err = s.db.Model(&model.WafService{}).Where("gateway_name = ?", req.GatewayName).First(wafService).Error
if err != nil {
if err == gorm.ErrRecordNotFound {
return fmt.Errorf("waf service not found for gateway %s", req.GatewayName)
}
return fmt.Errorf("failed to query waf service: %v", err)
}
mode := WafMode(wafService.Mode)
for _, port := range addingPortSet.List() { for _, port := range addingPortSet.List() {
err := s.EnableListenerWaf(ctx, &EnableListenerWafReq{ err := s.EnableListenerWaf(ctx, &EnableListenerWafReq{
GatewateInfo: GatewateInfo{ GatewateInfo: GatewateInfo{
...@@ -686,6 +699,7 @@ func (s *wafService) EnableListenerWafs(ctx context.Context, req *EnableListener ...@@ -686,6 +699,7 @@ func (s *wafService) EnableListenerWafs(ctx context.Context, req *EnableListener
Port: port, Port: port,
Hosts: wafMap[port], Hosts: wafMap[port],
Enable: true, Enable: true,
Mode: mode,
}) })
if err != nil { if err != nil {
return fmt.Errorf("failed to enable listener WAF: %v", err) return fmt.Errorf("failed to enable listener WAF: %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