rules

package
v0.1.72 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2019 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const (
	RuleOperatorGt          = "gt"
	RuleOperatorGte         = "gte"
	RuleOperatorLt          = "lt"
	RuleOperatorLte         = "lte"
	RuleOperatorEq          = "eq"
	RuleOperatorNeq         = "neq"
	RuleOperatorEqString    = "eq string"
	RuleOperatorNeqString   = "neq string"
	RuleOperatorMatch       = "match"
	RuleOperatorNotMatch    = "not match"
	RuleOperatorContains    = "contains"
	RuleOperatorNotContains = "not contains"
	RuleOperatorPrefix      = "prefix"
	RuleOperatorSuffix      = "suffix"
	RuleOperatorHasKey      = "has key" // has key in slice or map
	RuleOperatorVersionGt   = "version gt"
	RuleOperatorVersionLt   = "version lt"

	RuleCaseInsensitiveNone = "none"
	RuleCaseInsensitiveYes  = "yes"
	RuleCaseInsensitiveNo   = "no"
)
View Source
const (
	RuleConnectorAnd = "and"
	RuleConnectorOr  = "or"
)

Variables

View Source
var AllRuleOperators = []*RuleOperatorDefinition{
	{
		Name:            "数值大于",
		Code:            RuleOperatorGt,
		Description:     "使用数值对比大于",
		CaseInsensitive: RuleCaseInsensitiveNone,
	},
	{
		Name:            "数值大于等于",
		Code:            RuleOperatorGte,
		Description:     "使用数值对比大于等于",
		CaseInsensitive: RuleCaseInsensitiveNone,
	},
	{
		Name:            "数值小于",
		Code:            RuleOperatorLt,
		Description:     "使用数值对比小于",
		CaseInsensitive: RuleCaseInsensitiveNone,
	},
	{
		Name:            "数值小于等于",
		Code:            RuleOperatorLte,
		Description:     "使用数值对比小于等于",
		CaseInsensitive: RuleCaseInsensitiveNone,
	},
	{
		Name:            "数值等于",
		Code:            RuleOperatorEq,
		Description:     "使用数值对比等于",
		CaseInsensitive: RuleCaseInsensitiveNone,
	},
	{
		Name:            "数值不等于",
		Code:            RuleOperatorNeq,
		Description:     "使用数值对比不等于",
		CaseInsensitive: RuleCaseInsensitiveNone,
	},
	{
		Name:            "字符串等于",
		Code:            RuleOperatorEqString,
		Description:     "使用字符串对比等于",
		CaseInsensitive: RuleCaseInsensitiveNo,
	},
	{
		Name:            "字符串不等于",
		Code:            RuleOperatorNeqString,
		Description:     "使用字符串对比不等于",
		CaseInsensitive: RuleCaseInsensitiveNo,
	},
	{
		Name:            "正则匹配",
		Code:            RuleOperatorMatch,
		Description:     "使用正则表达式匹配,在头部使用(?i)表示不区分大小写,<a href=\"http://teaos.cn/doc/regexp/Regexp.md\" target=\"_blank\">正则表达式语法 &raquo;</a>",
		CaseInsensitive: RuleCaseInsensitiveYes,
	},
	{
		Name:            "正则不匹配",
		Code:            RuleOperatorNotMatch,
		Description:     "使用正则表达式不匹配,在头部使用(?i)表示不区分大小写,<a href=\"http://teaos.cn/doc/regexp/Regexp.md\" target=\"_blank\">正则表达式语法 &raquo;</a>",
		CaseInsensitive: RuleCaseInsensitiveYes,
	},
	{
		Name:            "包含字符串",
		Code:            RuleOperatorContains,
		Description:     "包含某个字符串",
		CaseInsensitive: RuleCaseInsensitiveNo,
	},
	{
		Name:            "不包含字符串",
		Code:            RuleOperatorNotContains,
		Description:     "不包含某个字符串",
		CaseInsensitive: RuleCaseInsensitiveNo,
	},
	{
		Name:            "包含前缀",
		Code:            RuleOperatorPrefix,
		Description:     "包含某个前缀",
		CaseInsensitive: RuleCaseInsensitiveNo,
	},
	{
		Name:            "包含后缀",
		Code:            RuleOperatorSuffix,
		Description:     "包含某个后缀",
		CaseInsensitive: RuleCaseInsensitiveNo,
	},
	{
		Name:            "包含索引",
		Code:            RuleOperatorHasKey,
		Description:     "对于一组数据拥有某个键值或者索引",
		CaseInsensitive: RuleCaseInsensitiveNo,
	},
	{
		Name:            "版本号大于",
		Code:            RuleOperatorVersionGt,
		Description:     "对于版本号大于",
		CaseInsensitive: RuleCaseInsensitiveNo,
	},
}

Functions

This section is empty.

Types

type Rule

type Rule struct {
	Param             string            `yaml:"param" json:"param"`       // such as ${arg.name} or ${args}, can be composite as ${arg.firstName}${arg.lastName}
	Operator          RuleOperator      `yaml:"operator" json:"operator"` // such as contains, gt,  ...
	Value             string            `yaml:"value" json:"value"`       // compared value
	IsCaseInsensitive bool              `yaml:"isCaseInsensitive" json:"isCaseInsensitive"`
	CheckpointOptions map[string]string `yaml:"checkpointOptions" json:"checkpointOptions"`
	// contains filtered or unexported fields
}

rule

func NewRule

func NewRule() *Rule

func (*Rule) Init

func (this *Rule) Init() error

func (*Rule) IsSingleCheckpoint

func (this *Rule) IsSingleCheckpoint() bool

func (*Rule) MatchRequest

func (this *Rule) MatchRequest(req *requests.Request) (b bool, err error)

func (*Rule) MatchResponse

func (this *Rule) MatchResponse(req *requests.Request, resp *requests.Response) (b bool, err error)

func (*Rule) SetCheckpointFinder

func (this *Rule) SetCheckpointFinder(finder func(prefix string) checkpoints.CheckpointInterface)

func (*Rule) Test

func (this *Rule) Test(value interface{}) bool

type RuleCaseInsensitive

type RuleCaseInsensitive = string

type RuleConnector

type RuleConnector = string

type RuleGroup

type RuleGroup struct {
	Id          string     `yaml:"id" json:"id"`
	On          bool       `yaml:"on" json:"on"`
	Name        string     `yaml:"name" json:"name"` // such as SQL Injection
	Description string     `yaml:"description" json:"description"`
	Code        string     `yaml:"code" json:"code"` // identify the group
	RuleSets    []*RuleSet `yaml:"ruleSets" json:"ruleSets"`
	IsInbound   bool       `yaml:"isInbound" json:"isInbound"`
	// contains filtered or unexported fields
}

rule group

func NewRuleGroup

func NewRuleGroup() *RuleGroup

func (*RuleGroup) AddRuleSet

func (this *RuleGroup) AddRuleSet(ruleSet *RuleSet)

func (*RuleGroup) FindRuleSet

func (this *RuleGroup) FindRuleSet(id string) *RuleSet

func (*RuleGroup) FindRuleSetWithCode

func (this *RuleGroup) FindRuleSetWithCode(code string) *RuleSet

func (*RuleGroup) Init

func (this *RuleGroup) Init() error

func (*RuleGroup) MatchRequest

func (this *RuleGroup) MatchRequest(req *requests.Request) (b bool, set *RuleSet, err error)

func (*RuleGroup) MatchResponse

func (this *RuleGroup) MatchResponse(req *requests.Request, resp *requests.Response) (b bool, set *RuleSet, err error)

func (*RuleGroup) MoveRuleSet

func (this *RuleGroup) MoveRuleSet(fromIndex int, toIndex int)

func (*RuleGroup) RemoveRuleSet

func (this *RuleGroup) RemoveRuleSet(id string)

type RuleOperator

type RuleOperator = string

type RuleOperatorDefinition

type RuleOperatorDefinition struct {
	Name            string
	Code            string
	Description     string
	CaseInsensitive RuleCaseInsensitive // default caseInsensitive setting
}

type RuleSet

type RuleSet struct {
	Id        string        `yaml:"id" json:"id"`
	Code      string        `yaml:"code" json:"code"`
	On        bool          `yaml:"on" json:"on"`
	Name      string        `yaml:"name" json:"name"`
	Rules     []*Rule       `yaml:"rules" json:"rules"`
	Connector RuleConnector `yaml:"connector" json:"connector"` // rules connector

	Action        actions.ActionString `yaml:"action" json:"action"`
	ActionOptions maps.Map             `yaml:"actionOptions" json:"actionOptions"` // TODO TO BE IMPLEMENTED
	// contains filtered or unexported fields
}

func NewRuleSet

func NewRuleSet() *RuleSet

func (*RuleSet) AddRule

func (this *RuleSet) AddRule(rule ...*Rule)

func (*RuleSet) Init

func (this *RuleSet) Init() error

func (*RuleSet) MatchRequest

func (this *RuleSet) MatchRequest(req *requests.Request) (b bool, err error)

func (*RuleSet) MatchResponse

func (this *RuleSet) MatchResponse(req *requests.Request, resp *requests.Response) (b bool, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL