Commit be45ca84 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Implement ListWafsV2 method and update API route

- Introduce ListWafsV2 method in WafController to enhance the WAF listing functionality with a new response structure.
- Update the API route for listing WAFs to point to the new ListWafsV2 method, improving clarity and consistency in the API design.
parent 037d412f
...@@ -36,7 +36,7 @@ func SetWafRouter(e *gin.Engine, clusterClientManager *utils.ClusterClientManage ...@@ -36,7 +36,7 @@ func SetWafRouter(e *gin.Engine, clusterClientManager *utils.ClusterClientManage
v2.PUT("blackwhitelist/enabling", wafController.EnableBlackWhiteList) v2.PUT("blackwhitelist/enabling", wafController.EnableBlackWhiteList)
v2.DELETE("blackwhitelist/:id", wafController.DeleteBlackWhiteList) v2.DELETE("blackwhitelist/:id", wafController.DeleteBlackWhiteList)
v2.GET("blackwhitelists", wafController.GetBlackWhiteLists) v2.GET("blackwhitelists", wafController.GetBlackWhiteLists)
v2.GET("services", wafController.ListWafs) v2.GET("services", wafController.ListWafsV2)
v2.GET("attack/classes", wafController.AttackClassesList) v2.GET("attack/classes", wafController.AttackClassesList)
} }
...@@ -58,6 +58,35 @@ func (c *WafController) ListWafs(ctx *gin.Context) { ...@@ -58,6 +58,35 @@ func (c *WafController) ListWafs(ctx *gin.Context) {
utils.AssembleResponse(ctx, wafs, nil) utils.AssembleResponse(ctx, wafs, nil)
} }
func (c *WafController) ListWafsV2(ctx *gin.Context) {
ctx1, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
wafs, err := c.service.ListWafs(ctx1)
if err != nil {
utils.AssembleResponse(ctx, nil, err)
return
}
type wafService struct {
Host string `json:"host"`
Namespace string `json:"namespace"`
}
type resp struct {
Items []wafService `json:"items"`
}
items := []wafService{}
for _, waf := range wafs {
items = append(items, wafService{
Host: waf.GatewayName,
})
}
utils.AssembleResponse(ctx, resp{Items: items}, nil)
}
func (c *WafController) GetWafGatewayInfo(ctx *gin.Context) { func (c *WafController) GetWafGatewayInfo(ctx *gin.Context) {
ctx1, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx1, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()
......
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