Commit 055b870b authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Update WAF service types and migration for listener configuration

- Modify `ListenerWaf` struct to use single `HostsAndPort` field instead of separate `Hosts` and `Port`
- Update `EnableListenerWafsReq` to use `ListenerWaf` slice for listeners
- Change `waf_services` table migration to use `BIGINT` and `AUTO_INCREMENT`
- Adjust `EnableListenerWafs` method to parse new listener format
- Add logging for listener name during WAF configuration
parent 7ba7c191
-- Create waf_services table
CREATE TABLE waf_services (
id SERIAL PRIMARY KEY,
id BIGINT PRIMARY KEY AUTO_INCREMENT,
gateway_name VARCHAR(255) NOT NULL,
namespace VARCHAR(255) NOT NULL,
region_code VARCHAR(50) NOT NULL,
......
......@@ -229,15 +229,16 @@ type EnableGatewayWafReq struct {
}
type ListenerWaf struct {
Hosts []string `json:"hosts"`
Port int `json:"port"`
Name string `json:"name"`
// Hosts []string `json:"hosts"`
// Port int `json:"port"`
HostsAndPort string `json:"hosts_and_port"`
Name string `json:"name"`
}
type EnableListenerWafsReq struct {
GatewateInfo
Enable bool `json:"enable"`
Listeners []string `json:"listeners"`
Enable bool `json:"enable"`
Listeners []ListenerWaf `json:"listeners"`
}
type WafRule struct {
......
......@@ -606,18 +606,19 @@ func (s *wafService) EnableListenerWafs(ctx context.Context, req *EnableListener
wafMap := map[int][]string{}
for _, listener := range req.Listeners {
// get port from listener, like hosts1@127.0.0.1@abc.com-8080
index := strings.LastIndex(listener, "-")
index := strings.LastIndex(listener.HostsAndPort, "-")
if index == -1 {
return fmt.Errorf("failed to get listener port: %v", listener)
}
port := listener[index+1:]
port := listener.HostsAndPort[index+1:]
portInt, err := strconv.Atoi(port)
if err != nil {
return fmt.Errorf("failed to parse listener port: %v", err)
}
desiredPortSet.Insert(portInt)
log.Info().Msgf("listener: %v", listener.Name)
hosts := strings.Split(listener, "@")
hosts := strings.Split(listener.HostsAndPort, "@")
wafMap[portInt] = hosts
}
......
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