mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-07 23:30:25 +08:00
自动将API节点的IP加入到白名单,防止误封
This commit is contained in:
@@ -51,6 +51,8 @@ type NodeConfig struct {
|
|||||||
|
|
||||||
MetricItems []*serverconfigs.MetricItemConfig `yaml:"metricItems" json:"metricItems"`
|
MetricItems []*serverconfigs.MetricItemConfig `yaml:"metricItems" json:"metricItems"`
|
||||||
|
|
||||||
|
AllowedIPs []string `yaml:"allowedIPs" json:"allowedIPs"` // 自动白名单
|
||||||
|
|
||||||
paddedId string
|
paddedId string
|
||||||
|
|
||||||
// firewall
|
// firewall
|
||||||
@@ -61,6 +63,9 @@ type NodeConfig struct {
|
|||||||
|
|
||||||
// 源站集合
|
// 源站集合
|
||||||
originMap map[int64]*serverconfigs.OriginConfig
|
originMap map[int64]*serverconfigs.OriginConfig
|
||||||
|
|
||||||
|
// 自动白名单
|
||||||
|
allowedIPMap map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// SharedNodeConfig 取得当前节点配置单例
|
// SharedNodeConfig 取得当前节点配置单例
|
||||||
@@ -218,6 +223,12 @@ func (this *NodeConfig) Init() (err error, serverErrors []*ServerError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 自动白名单
|
||||||
|
this.allowedIPMap = map[string]bool{}
|
||||||
|
for _, allowIP := range this.AllowedIPs {
|
||||||
|
this.allowedIPMap[allowIP] = true
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,3 +333,9 @@ func (this *NodeConfig) lookupWeb(server *serverconfigs.ServerConfig, web *serve
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IPIsAutoAllowed 检查是否自动允许某个IP
|
||||||
|
func (this *NodeConfig) IPIsAutoAllowed(ip string) bool {
|
||||||
|
_, ok := this.allowedIPMap[ip]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user