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 {
RuleNum int `gorm:"column:rule_num"`
AttackNum int `gorm:"column:attack_num"`
RuleCategoryStatus *RuleCategoryStatus `gorm:"column:rule_category_status;type:json"`
// ListenerWafs string `gorm:"column:listener_wafs"`
// Host HostList `gorm:"column:host"`
}
......
......@@ -164,10 +164,11 @@ type IPInfoPrivateResp struct {
}
type WafService struct {
GatewayName string `json:"gateway_name"`
Mode string `json:"mode"`
RuleNum int `json:"rule_num"`
AttackNum int `json:"attack_num"`
GatewayName string `json:"gateway_name"`
Mode string `json:"mode"`
RuleNum int `json:"rule_num"`
AttackNum int `json:"attack_num"`
Listeners []string `json:"listeners"`
} // WAF configuration details
type GatewateInfo struct {
......@@ -270,11 +271,12 @@ type WafRuleCategory struct {
}
type GatewayListener struct {
GatewayName string `json:"gateway_name"`
Namespace string `json:"namespace"`
RegionCode string `json:"region_code"`
Port int `json:"port"`
Enable bool `json:"enable"`
GatewayName string `json:"gateway_name"`
Namespace string `json:"namespace"`
RegionCode string `json:"region_code"`
Hosts []string `json:"hosts"`
Port int `json:"port"`
Enable bool `json:"enable"`
}
type CreateListenerReq struct {
......
......@@ -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)
}
}
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{
GatewayName: wafService.GatewayName,
Mode: wafService.Mode,
RuleNum: wafService.RuleNum,
AttackNum: wafService.AttackNum,
Listeners: listeners,
}, nil
}
......@@ -548,7 +563,6 @@ func (s *wafService) ListListenerWafStatus(ctx context.Context, req *GatewateInf
}
listenerStatusList := []*GatewayListener{}
portList := []int{}
for _, listener := range listenerList.Items {
n := strings.LastIndex(listener.Name, "-")
if n == -1 {
......@@ -559,19 +573,28 @@ func (s *wafService) ListListenerWafStatus(ctx context.Context, req *GatewateInf
if err != nil {
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{
GatewayName: req.GatewayName,
Namespace: req.Namespace,
RegionCode: req.RegionCode,
Port: port,
Enable: true,
Port: listenerPortInt,
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
}
......
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