rule

package
v0.0.0-...-3f1871c Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2017 License: MIT, MIT Imports: 5 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRuleNotFound = errors.New("vinxi: rule does not exists")

ErrRuleNotFound is used when a rule does not exists.

View Source
var Rules = make(map[string]Info)

Rules is used to store the existent rules globally.

Functions

func Exists

func Exists(name string) bool

Exists is used to check if a given rule name exists.

func New

func New(info Info) func(config.Config) (Rule, error)

New creates a new rule entity based on the given matcher function.

func Register

func Register(rule Info)

Register registers the given rule in the current store.

func Validate

func Validate(params Params, opts config.Config) error

Validate is used to validates the rule params and report the proper param specific error.

Types

type Factory

type Factory func(config.Config) (Matcher, error)

Factory represents the rule factory function interface.

func GetFactory

func GetFactory(name string) Factory

GetFactory is used to find and retrieve a rule factory function.

type Field

type Field struct {
	Name        string      `json:"name,omitempty"`
	Type        string      `json:"type,omitempty"`
	Description string      `json:"description,omitempty"`
	Mandatory   bool        `json:"mandatory,omitempty"`
	Examples    []string    `json:"examples,omitempty"`
	Default     interface{} `json:"default,omitempty"`
	Validator   Validator   `json:"-"`
}

Field is used to declare specific config fields supported by rules.

type Info

type Info struct {
	Name        string  `json:"name,omitempty"`
	Description string  `json:"description,omitempty"`
	Params      Params  `json:"params,omitempty"`
	Factory     Factory `json:"-"`
}

Info represents the rule entity fields storing the name, description and factory function used to initialize the fields.

func GetInfo

func GetInfo(name string) Info

GetInfo is used to find and retrieve a rule info struct, if exists.

type Layer

type Layer struct {
	// contains filtered or unexported fields
}

Layer represents a rules layer designed to intrument proxies providing plugin based dynamic configuration capabilities, such as register/unregister or enable/disable rules at runtime satefy.

func NewLayer

func NewLayer() *Layer

NewLayer creates a new rules layer.

func (*Layer) All

func (l *Layer) All() []Rule

All returns the slice of registered rules.

func (*Layer) Flush

func (l *Layer) Flush()

Flush removes all the registered rules.

func (*Layer) Get

func (l *Layer) Get(name string) Rule

Get finds and treturns a rule instance.

func (*Layer) Len

func (l *Layer) Len() int

Len returns the registered rules length.

func (*Layer) Match

func (l *Layer) Match(r *http.Request) bool

Match matches the given http.Request agains the registered rules. If all the rules passes it will return true, otherwise false.

func (*Layer) Remove

func (l *Layer) Remove(id string) bool

Remove removes a rule looking by its unique identifier.

func (*Layer) Use

func (l *Layer) Use(rule ...Rule)

Use registers one or multiples plugins in the current rule layer.

type Matcher

type Matcher func(*http.Request) bool

Matcher represents the matching function interface used by rules to determine if a given traffic should be filtered or not.

type NewFunc

type NewFunc func(config.Config) (Rule, error)

NewFunc represents the Rule constructor factory function interface.

func Get

func Get(name string) NewFunc

Get is used to find and retrieve a rule factory function.

type Params

type Params []Field

Params represents the list of supported config fields by rules.

type Rule

type Rule interface {
	// ID returns the rule unique identifier.
	ID() string
	// Name returns the rule semantic alias.
	Name() string
	// Description is used to retrieve the rule semantic description.
	Description() string
	// Config is used to retrieve the rule config.
	Config() config.Config
	// Match is used to determine if a given http.Request
	// passes the rule assertion.
	Match(*http.Request) bool
}

Rule represents the required interface implemented by HTTP traffic rules.

Rule is designed to inspect an incoming HTTP traffic and determine if should trigger the registered plugins if the rule matches.

func Init

func Init(name string, opts config.Config) (Rule, error)

Init is used to initialize a new rule by name identifier based on the given config options.

func NewWithConfig

func NewWithConfig(info Info, opts config.Config) (Rule, error)

NewWithConfig creates a new rule entity based on the given config and matcher function.

type Validator

type Validator func(interface{}, config.Config) error

Validator represents the rule config field validator function interface.

Jump to

Keyboard shortcuts

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