From feee41d474ff35eab9d543e056667c61debaa10c Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Mon, 6 Dec 2021 10:09:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=B0=86API=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E7=9A=84IP=E5=8A=A0=E5=85=A5=E5=88=B0=E7=99=BD?= =?UTF-8?q?=E5=90=8D=E5=8D=95=EF=BC=8C=E9=98=B2=E6=AD=A2=E8=AF=AF=E5=B0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/nodeconfigs/node_config.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/nodeconfigs/node_config.go b/pkg/nodeconfigs/node_config.go index 9f608e4..9f12d37 100644 --- a/pkg/nodeconfigs/node_config.go +++ b/pkg/nodeconfigs/node_config.go @@ -51,6 +51,8 @@ type NodeConfig struct { MetricItems []*serverconfigs.MetricItemConfig `yaml:"metricItems" json:"metricItems"` + AllowedIPs []string `yaml:"allowedIPs" json:"allowedIPs"` // 自动白名单 + paddedId string // firewall @@ -61,6 +63,9 @@ type NodeConfig struct { // 源站集合 originMap map[int64]*serverconfigs.OriginConfig + + // 自动白名单 + allowedIPMap map[string]bool } // 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 } @@ -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 +}