5秒盾支持例外URL和限制URL

This commit is contained in:
GoEdgeLab
2023-03-06 21:49:11 +08:00
parent a7f5980de8
commit 5bd22ba4c3
6 changed files with 272 additions and 1 deletions

View File

@@ -2,12 +2,55 @@
package serverconfigs
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"`
OnlyURLPatterns []*shared.URLPattern `yaml:"onlyURLPatterns" json:"onlyURLPatterns"` // 仅限的URL
ExceptURLPatterns []*shared.URLPattern `yaml:"exceptURLPatterns" json:"exceptURLPatterns"` // 排除的URL
}
func (this *UAMConfig) Init() error {
// only urls
for _, pattern := range this.OnlyURLPatterns {
err := pattern.Init()
if err != nil {
return err
}
}
// except urls
for _, pattern := range this.ExceptURLPatterns {
err := pattern.Init()
if err != nil {
return err
}
}
return nil
}
func (this *UAMConfig) MatchURL(url string) bool {
// except
if len(this.ExceptURLPatterns) > 0 {
for _, pattern := range this.ExceptURLPatterns {
if pattern.Match(url) {
return false
}
}
}
if len(this.OnlyURLPatterns) > 0 {
for _, pattern := range this.OnlyURLPatterns {
if pattern.Match(url) {
return true
}
}
return false
}
return true
}