Commit c5861eb6 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

commit

parent 3a60031f
......@@ -163,7 +163,7 @@ type IPInfoPrivateResp struct {
VerboseMsg string `json:"verbose_msg"`
}
type Waf struct {
type WafService struct {
GatewayName string `json:"gateway_name"`
Mode string `json:"mode"`
RuleNum int `json:"rule_num"`
......
......@@ -23,14 +23,29 @@ func NewWafService(client *versioned.Clientset, db *gorm.DB) Service {
return &wafService{client: client, db: db}
}
func (s *wafService) GetWaf(ctx context.Context, gatewayName string) (*Waf, error) {
waf := &Waf{
GatewayName: gatewayName,
Mode: "block",
RuleNum: 100,
AttackNum: 100,
func (s *wafService) GetWaf(ctx context.Context, gatewayName string) (*WafService, error) {
wafService := &model.WafService{}
err := s.db.Model(&model.WafService{}).Where("gateway_name = ?", gatewayName).First(wafService).Error
if err != nil {
if err == gorm.ErrRecordNotFound {
// Create new WAF service record if not found
wafService = &model.WafService{
GatewayName: gatewayName,
Mode: string(WafModeAlert),
}
if err := s.db.Create(wafService).Error; err != nil {
return nil, fmt.Errorf("failed to create WAF service: %v", err)
}
} else {
return nil, fmt.Errorf("failed to query WAF service: %v", err)
}
}
return waf, nil
return &WafService{
GatewayName: wafService.GatewayName,
Mode: wafService.Mode,
RuleNum: wafService.RuleNum,
AttackNum: wafService.AttackNum,
}, nil
}
func (s *wafService) CreateWaf(ctx context.Context, req *CreateWafReq) (*Waf, error) {
......
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