Commit 75afb8d4 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Add listener details to WAF service response

- Modify `WafService` struct to include listener information
- Update `GetWaf` method to retrieve and format listener details
- Enhance `ListListenerWafStatus` to return hosts for each listener
- Remove commented-out code and unused port list logic
parent 286f81ee
...@@ -56,6 +56,7 @@ type WafService struct { ...@@ -56,6 +56,7 @@ type WafService struct {
RuleNum int `gorm:"column:rule_num"` RuleNum int `gorm:"column:rule_num"`
AttackNum int `gorm:"column:attack_num"` AttackNum int `gorm:"column:attack_num"`
RuleCategoryStatus *RuleCategoryStatus `gorm:"column:rule_category_status;type:json"` RuleCategoryStatus *RuleCategoryStatus `gorm:"column:rule_category_status;type:json"`
// ListenerWafs string `gorm:"column:listener_wafs"`
// Host HostList `gorm:"column:host"` // Host HostList `gorm:"column:host"`
} }
......
...@@ -164,10 +164,11 @@ type IPInfoPrivateResp struct { ...@@ -164,10 +164,11 @@ type IPInfoPrivateResp struct {
} }
type WafService struct { type WafService struct {
GatewayName string `json:"gateway_name"` GatewayName string `json:"gateway_name"`
Mode string `json:"mode"` Mode string `json:"mode"`
RuleNum int `json:"rule_num"` RuleNum int `json:"rule_num"`
AttackNum int `json:"attack_num"` AttackNum int `json:"attack_num"`
Listeners []string `json:"listeners"`
} // WAF configuration details } // WAF configuration details
type GatewateInfo struct { type GatewateInfo struct {
...@@ -270,11 +271,12 @@ type WafRuleCategory struct { ...@@ -270,11 +271,12 @@ type WafRuleCategory struct {
} }
type GatewayListener struct { type GatewayListener struct {
GatewayName string `json:"gateway_name"` GatewayName string `json:"gateway_name"`
Namespace string `json:"namespace"` Namespace string `json:"namespace"`
RegionCode string `json:"region_code"` RegionCode string `json:"region_code"`
Port int `json:"port"` Hosts []string `json:"hosts"`
Enable bool `json:"enable"` Port int `json:"port"`
Enable bool `json:"enable"`
} }
type CreateListenerReq struct { type CreateListenerReq struct {
......
...@@ -51,11 +51,26 @@ func (s *wafService) GetWaf(ctx context.Context, regionCode, namespace, gatewayN ...@@ -51,11 +51,26 @@ func (s *wafService) GetWaf(ctx context.Context, regionCode, namespace, gatewayN
return nil, fmt.Errorf("failed to query WAF service: %v", err) return nil, fmt.Errorf("failed to query WAF service: %v", err)
} }
} }
listenerWafs, err := s.ListListenerWafStatus(ctx, &GatewateInfo{
GatewayName: gatewayName,
Namespace: namespace,
RegionCode: regionCode,
})
if err != nil {
return nil, fmt.Errorf("failed to list listener WAF status: %v", err)
}
listeners := []string{}
for _, listener := range listenerWafs {
hosts := strings.Join(listener.Hosts, "@")
listeners = append(listeners, fmt.Sprintf("%s-%d", hosts, listener.Port))
}
return &WafService{ return &WafService{
GatewayName: wafService.GatewayName, GatewayName: wafService.GatewayName,
Mode: wafService.Mode, Mode: wafService.Mode,
RuleNum: wafService.RuleNum, RuleNum: wafService.RuleNum,
AttackNum: wafService.AttackNum, AttackNum: wafService.AttackNum,
Listeners: listeners,
}, nil }, nil
} }
...@@ -548,7 +563,6 @@ func (s *wafService) ListListenerWafStatus(ctx context.Context, req *GatewateInf ...@@ -548,7 +563,6 @@ func (s *wafService) ListListenerWafStatus(ctx context.Context, req *GatewateInf
} }
listenerStatusList := []*GatewayListener{} listenerStatusList := []*GatewayListener{}
portList := []int{}
for _, listener := range listenerList.Items { for _, listener := range listenerList.Items {
n := strings.LastIndex(listener.Name, "-") n := strings.LastIndex(listener.Name, "-")
if n == -1 { if n == -1 {
...@@ -559,19 +573,28 @@ func (s *wafService) ListListenerWafStatus(ctx context.Context, req *GatewateInf ...@@ -559,19 +573,28 @@ func (s *wafService) ListListenerWafStatus(ctx context.Context, req *GatewateInf
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to parse listener port: %v", err) return nil, fmt.Errorf("failed to parse listener port: %v", err)
} }
portList = append(portList, listenerPortInt)
}
for _, port := range portList { // hosts := strings.Join(listener.Spec.HostNames, "@")
// log.Info().Msgf("hosts: %v", hosts)
listenerStatusList = append(listenerStatusList, &GatewayListener{ listenerStatusList = append(listenerStatusList, &GatewayListener{
GatewayName: req.GatewayName, GatewayName: req.GatewayName,
Namespace: req.Namespace, Namespace: req.Namespace,
RegionCode: req.RegionCode, RegionCode: req.RegionCode,
Port: port, Port: listenerPortInt,
Enable: true, Hosts: listener.Spec.HostNames,
}) })
} }
// for _, port := range portList {
// listenerStatusList = append(listenerStatusList, &GatewayListener{
// GatewayName: req.GatewayName,
// Namespace: req.Namespace,
// RegionCode: req.RegionCode,
// Port: port,
// Enable: true,
// })
// }
return listenerStatusList, nil return listenerStatusList, nil
} }
......
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