2020-10-06 21:02:21 +08:00
|
|
|
package firewallconfigs
|
|
|
|
|
|
2020-11-18 19:48:27 +08:00
|
|
|
import (
|
|
|
|
|
"regexp"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var namedParamReg = regexp.MustCompile(`^\${\s*(.+)\s*}$`)
|
|
|
|
|
|
2020-10-06 21:02:21 +08:00
|
|
|
type HTTPFirewallRule struct {
|
|
|
|
|
Id int64 `yaml:"id" json:"id"`
|
|
|
|
|
IsOn bool `yaml:"isOn" json:"isOn"`
|
|
|
|
|
Param string `yaml:"param" json:"param"`
|
2020-11-21 20:44:00 +08:00
|
|
|
ParamFilters []*ParamFilter `yaml:"paramFilters" json:"paramFilters"`
|
2020-10-06 21:02:21 +08:00
|
|
|
Operator string `yaml:"operator" json:"operator"`
|
|
|
|
|
Value string `yaml:"value" json:"value"`
|
|
|
|
|
IsCaseInsensitive bool `yaml:"isCaseInsensitive" json:"isCaseInsensitive"`
|
|
|
|
|
CheckpointOptions map[string]interface{} `yaml:"checkpointOptions" json:"checkpointOptions"`
|
|
|
|
|
Description string `yaml:"description" json:"description"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *HTTPFirewallRule) Init() error {
|
2020-10-08 11:11:29 +08:00
|
|
|
// TODO 执行更严谨的校验
|
2020-10-06 21:02:21 +08:00
|
|
|
return nil
|
|
|
|
|
}
|
2020-11-18 19:48:27 +08:00
|
|
|
|
|
|
|
|
func (this *HTTPFirewallRule) Prefix() string {
|
|
|
|
|
result := namedParamReg.FindStringSubmatch(this.Param)
|
|
|
|
|
if len(result) > 0 {
|
|
|
|
|
param := result[1]
|
|
|
|
|
pieces := strings.Split(param, ".")
|
|
|
|
|
return pieces[0]
|
|
|
|
|
}
|
|
|
|
|
return this.Param
|
|
|
|
|
}
|