From 67642ebe1dada08dd432a2eaef98584da4cc18fa Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Fri, 12 Jan 2024 17:13:34 +0800 Subject: [PATCH] =?UTF-8?q?5=E7=A7=92=E7=9B=BE=E5=A2=9E=E5=8A=A0=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/serverconfigs/uam_config.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/pkg/serverconfigs/uam_config.go b/pkg/serverconfigs/uam_config.go index 3338f5c..ebf5baf 100644 --- a/pkg/serverconfigs/uam_config.go +++ b/pkg/serverconfigs/uam_config.go @@ -2,17 +2,20 @@ package serverconfigs -import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" +import ( + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" +) // UAMConfig UAM配置 type UAMConfig struct { IsPrior bool `yaml:"isPrior" json:"isPrior"` IsOn bool `yaml:"isOn" json:"isOn"` - AddToWhiteList bool `yaml:"addToWhiteList" json:"addToWhiteList"` // 是否将IP加入到白名单 - OnlyURLPatterns []*shared.URLPattern `yaml:"onlyURLPatterns" json:"onlyURLPatterns"` // 仅限的URL - ExceptURLPatterns []*shared.URLPattern `yaml:"exceptURLPatterns" json:"exceptURLPatterns"` // 排除的URL - MinQPSPerIP int `yaml:"minQPSPerIP" json:"minQPSPerIP"` // 启用要求的单IP最低平均QPS + AddToWhiteList bool `yaml:"addToWhiteList" json:"addToWhiteList"` // 是否将IP加入到白名单 + OnlyURLPatterns []*shared.URLPattern `yaml:"onlyURLPatterns" json:"onlyURLPatterns"` // 仅限的URL + ExceptURLPatterns []*shared.URLPattern `yaml:"exceptURLPatterns" json:"exceptURLPatterns"` // 排除的URL + MinQPSPerIP int `yaml:"minQPSPerIP" json:"minQPSPerIP"` // 启用要求的单IP最低平均QPS + Conds *shared.HTTPRequestCondsConfig `yaml:"conds" json:"conds"` // 匹配条件 } func NewUAMConfig() *UAMConfig { @@ -38,6 +41,14 @@ func (this *UAMConfig) Init() error { } } + // conds + if this.Conds != nil { + err := this.Conds.Init() + if err != nil { + return err + } + } + return nil } @@ -62,3 +73,10 @@ func (this *UAMConfig) MatchURL(url string) bool { return true } + +func (this *UAMConfig) MatchRequest(formatter func(s string) string) bool { + if this.Conds == nil { + return true + } + return this.Conds.MatchRequest(formatter) +}