feat(auth): refactor IP restriction handling to use clearer variable naming
This commit is contained in:
+3
-3
@@ -242,8 +242,8 @@ func TokenAuth() func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
allowIpsMap := token.GetIpLimits()
|
allowIps := token.GetIpLimits()
|
||||||
if len(allowIpsMap) > 0 {
|
if len(allowIps) > 0 {
|
||||||
clientIp := c.ClientIP()
|
clientIp := c.ClientIP()
|
||||||
logger.LogDebug(c, "Token has IP restrictions, checking client IP %s", clientIp)
|
logger.LogDebug(c, "Token has IP restrictions, checking client IP %s", clientIp)
|
||||||
ip := net.ParseIP(clientIp)
|
ip := net.ParseIP(clientIp)
|
||||||
@@ -251,7 +251,7 @@ func TokenAuth() func(c *gin.Context) {
|
|||||||
abortWithOpenAiMessage(c, http.StatusForbidden, "无法解析客户端 IP 地址")
|
abortWithOpenAiMessage(c, http.StatusForbidden, "无法解析客户端 IP 地址")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if common.IsIpInCIDRList(ip, allowIpsMap) == false {
|
if common.IsIpInCIDRList(ip, allowIps) == false {
|
||||||
abortWithOpenAiMessage(c, http.StatusForbidden, "您的 IP 不在令牌允许访问的列表中")
|
abortWithOpenAiMessage(c, http.StatusForbidden, "您的 IP 不在令牌允许访问的列表中")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user