Commit f2ae41c0 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

commit

parent 6ec9f2d9
......@@ -13,4 +13,5 @@ func SetWafRouter(e *gin.Engine, client *versioned.Clientset, db *gorm.DB) {
wafController := controller.NewWafController(client, db)
v1.GET("waf/:gateway_name", wafController.Waf)
v1.POST("waf", wafController.CreateWaf)
v1.PUT("mode", wafController.UpdateMode)
}
......@@ -41,7 +41,7 @@ require (
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.27.2 // indirect
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c // indirect
......
......@@ -70,3 +70,21 @@ func (c *WafController) CreateWaf(ctx *gin.Context) {
// }
// ]'
// `
func (c *WafController) UpdateMode(ctx *gin.Context) {
ctx1, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
var req service.UpdateModeReq
if err := ctx.BindJSON(&req); err != nil {
utils.AssembleResponse(ctx, nil, err)
return
}
_, err := c.service.UpdateMode(ctx1, &req)
if err != nil {
utils.AssembleResponse(ctx, nil, err)
return
}
utils.AssembleResponse(ctx, nil, nil)
}
......@@ -17,17 +17,36 @@ func (h *HostList) Scan(src interface{}) error {
return nil
}
type Waf struct {
ID uint `gorm:"column:id;primaryKey;autoIncrement"`
GatewayName string `gorm:"column:gateway_name"`
Port int `gorm:"column:port"`
Namespace string `gorm:"column:namespace"`
RegionCode string `gorm:"column:region_code"`
Host HostList `gorm:"column:host"`
type RuleCategoryStatus struct {
CategoryID string `json:"category_id"`
Status int `json:"status"`
}
func (Waf) TableName() string {
return "waf"
type RuleCategoryStatusList []RuleCategoryStatus
func (r RuleCategoryStatusList) Value() (driver.Value, error) {
return json.Marshal(r)
}
func (r *RuleCategoryStatusList) Scan(src interface{}) error {
return json.Unmarshal(src.([]byte), r)
}
type WafService struct {
ID uint `gorm:"column:id;primaryKey;autoIncrement"`
GatewayName string `gorm:"column:gateway_name"`
Port int `gorm:"column:port"`
Namespace string `gorm:"column:namespace"`
RegionCode string `gorm:"column:region_code"`
Host HostList `gorm:"column:host"`
Mode string `gorm:"column:mode"`
RuleNum int `gorm:"column:rule_num"`
AttackNum int `gorm:"column:attack_num"`
RuleCategoryStatus RuleCategoryStatusList `gorm:"column:rule_category_status;type:json"`
}
func (WafService) TableName() string {
return "waf_services"
}
type WafRule struct {
......
......@@ -6,4 +6,5 @@ type Service interface {
// QueryIP(ip string) (*model.IPInfo, error)
GetWaf(ctx context.Context, gatewayName string) (*Waf, error)
CreateWaf(ctx context.Context, req *CreateWafReq) (*Waf, error)
UpdateMode(ctx context.Context, req *UpdateModeReq) (*Waf, error)
}
......@@ -182,3 +182,10 @@ type RuleRequest struct {
CategoryID []string `json:"category_id"`
Status int `json:"status"`
}
type UpdateModeReq struct {
Mode string `json:"mode"`
GatewayName string `json:"gateway_name"`
Namespace string `json:"namespace"`
RegionCode string `json:"region_code"`
}
......@@ -52,3 +52,7 @@ func (s *wafService) CreateWaf(ctx context.Context, req *CreateWafReq) (*Waf, er
return nil, nil
}
func (s *wafService) UpdateMode(ctx context.Context, req *UpdateModeReq) (*Waf, error) {
return nil, 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