Explorar el Código

refactor(waf): 优化 IP 黑名单差异计算逻辑

- 移除了对旧 IP 列表和新 IP 列表的空列表判断
- 添加了注释,明确代码功能
-通过直接迭代列表来提取有效 IP 地址,提高了代码可读性和效率
fusu hace 22 horas
padre
commit
363f7d986b
Se han modificado 1 ficheros con 11 adiciones y 10 borrados
  1. 11 10
      internal/service/api/waf/aidedweb.go

+ 11 - 10
internal/service/api/waf/aidedweb.go

@@ -372,20 +372,21 @@ func (s *aidedWebService) FindDifferenceList(oldList, newList []v1.BackendList)
 func (s *aidedWebService) WashDifferentIp(newIpList []string, oldIpList []string) (addedDenyIps []string, removedDenyIps []string) {
 	var newAllowIps []string
 	var oldAllowIps []string
-	if len(oldIpList) > 0 {
-		for _, v := range oldIpList {
-			if net.ParseIP(v) != nil {
-				oldAllowIps = append(oldAllowIps, v)
-			}
+
+	// 获取旧IP列表
+	for _, v := range oldIpList {
+		if net.ParseIP(v) != nil {
+			oldAllowIps = append(oldAllowIps, v)
 		}
 	}
-	if len(newIpList) > 0 {
-		for _, v := range newIpList {
-			if net.ParseIP(v) != nil {
-				newAllowIps = append(newAllowIps, v)
-			}
+
+	// 获取新IP列表
+	for _, v := range newIpList {
+		if net.ParseIP(v) != nil {
+			newAllowIps = append(newAllowIps, v)
 		}
 	}
+	
 	addedDenyIps, removedDenyIps = s.wafformatter.findIpDifferences(oldAllowIps, newAllowIps)
 	return addedDenyIps, removedDenyIps
 }