فهرست منبع

fix(waf): 增加配置实例的检查

在处理 allowanddenyip 请求时,增加了对 gatewayGroupIps 长度的检查。
如果长度为 0,返回错误提示用户先配置实例。
这个检查在以下几个地方进行了添加:
- 新增 ip 时- 更新 ip 时
- 删除 ip 时

这样可以避免在没有配置实例的情况下进行 IP 黑白名单操作,提高系统稳定性。
fusu 1 هفته پیش
والد
کامیت
029ea8870c
1فایلهای تغییر یافته به همراه15 افزوده شده و 0 حذف شده
  1. 15 0
      internal/service/api/waf/allowanddenyip.go

+ 15 - 0
internal/service/api/waf/allowanddenyip.go

@@ -66,6 +66,9 @@ func (s *allowAndDenyIpService) AddAllowAndDenyIps(ctx context.Context, req v1.A
 	if err != nil {
 		return err
 	}
+	if len(gatewayGroupIps) == 0 {
+		return fmt.Errorf("请先配置实例")
+	}
 
 	color := "black"
 	if req.AllowOrDeny == 1 {
@@ -99,6 +102,12 @@ func (s *allowAndDenyIpService) EditAllowAndDenyIps(ctx context.Context, req v1.
 	if err != nil {
 		return err
 	}
+
+	if len(gatewayGroupIps) == 0 {
+		return fmt.Errorf("请先配置实例")
+	}
+
+
 	color := "black"
 	if req.AllowOrDeny == 1 {
 		color = "white"
@@ -138,6 +147,12 @@ func (s *allowAndDenyIpService) DeleteAllowAndDenyIps(ctx context.Context, req v
 		if err != nil {
 			return err
 		}
+
+		if len(gatewayGroupIps) == 0 {
+			return fmt.Errorf("请先配置实例")
+		}
+
+
 		ip, err := s.GetAllowAndDenyIp(ctx, int64(id))
 		if err != nil {
 			return err