rules

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyRuleType   = errors.New("empty rule type")
	ErrInvalidRuleArgs = errors.New("invalid rule arguments")
	ErrOddOrZero       = errors.New("data length is odd or equal zero")
	ErrCaseMismatch    = errors.New("case mismatch")
)

Functions

func GetRuleBase

func GetRuleBase() map[string]RuleBaseCreator

func GetRuleWrappers

func GetRuleWrappers() map[string]RuleWrapperCreator

func PrepareMany

func PrepareMany(
	rules []Rule,
	e wrapper.Entity,
	logger zerolog.Logger,
) error

Types

type CompositeAndRule

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

func (CompositeAndRule) Apply

func (f CompositeAndRule) Apply(
	e wrapper.Entity,
	logger zerolog.Logger,
) (bool, error)

func (CompositeAndRule) Prepare

func (f CompositeAndRule) Prepare(
	e wrapper.Entity,
	logger zerolog.Logger,
) error

func (CompositeAndRule) String

func (f CompositeAndRule) String() string

type CompositeAndRuleParams

type CompositeAndRuleParams struct {
	Rules []string `mapstructure:"rules"`
}

type CompositeNotRule

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

func (CompositeNotRule) Apply

func (f CompositeNotRule) Apply(
	e wrapper.Entity,
	logger zerolog.Logger,
) (bool, error)

func (CompositeNotRule) Prepare

func (f CompositeNotRule) Prepare(
	e wrapper.Entity,
	logger zerolog.Logger,
) error

func (CompositeNotRule) String

func (f CompositeNotRule) String() string

type CompositeNotRuleParams

type CompositeNotRuleParams struct {
	Rule string `mapstructure:"rule"`
}

type CompositeOrRule

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

func (CompositeOrRule) Apply

func (f CompositeOrRule) Apply(
	e wrapper.Entity,
	logger zerolog.Logger,
) (bool, error)

func (CompositeOrRule) Prepare

func (f CompositeOrRule) Prepare(
	e wrapper.Entity,
	logger zerolog.Logger,
) error

func (CompositeOrRule) String

func (f CompositeOrRule) String() string

type CompositeOrRuleParams

type CompositeOrRuleParams struct {
	Rules []string `mapstructure:"rules"`
}

type GeoParam

type GeoParam struct {
	Organisation []string `mapstructure:"organisation"`
	CountryCode  []string `mapstructure:"country_code"`
	Country      []string `mapstructure:"country"`
	RegionCode   []string `mapstructure:"region_code"`
	Region       []string `mapstructure:"region"`
	City         []string `mapstructure:"city"`
	Timezone     []string `mapstructure:"timezone"`
	ASN          []string `mapstructure:"asn"`
}

NOTE: GeoParam and GeoRegexp must have same field names.

type GeoParams

type GeoParams struct {
	Path         string     `mapstructure:"list"`
	Geolocations []GeoParam `mapstructure:"geolocations"`
}

type GeoRegexp

type GeoRegexp struct {
	Organisation []*regexp.Regexp
	CountryCode  []*regexp.Regexp
	Country      []*regexp.Regexp
	RegionCode   []*regexp.Regexp
	Region       []*regexp.Regexp
	City         []*regexp.Regexp
	Timezone     []*regexp.Regexp
	ASN          []*regexp.Regexp
}

func (*GeoRegexp) String

func (r *GeoRegexp) String() string

type GeoRule

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

func (*GeoRule) Apply

func (f *GeoRule) Apply(
	e wrapper.Entity,
	logger zerolog.Logger,
) (bool, error)

func (*GeoRule) Prepare

func (f *GeoRule) Prepare(
	e wrapper.Entity,
	logger zerolog.Logger,
) error

func (*GeoRule) String

func (f *GeoRule) String() string

type IPRule

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

func (*IPRule) Apply

func (f *IPRule) Apply(
	e wrapper.Entity,
	logger zerolog.Logger,
) (bool, error)

func (*IPRule) Prepare

func (f *IPRule) Prepare(
	_ wrapper.Entity,
	_ zerolog.Logger,
) error

func (*IPRule) String

func (f *IPRule) String() string

type IPRuleParams

type IPRuleParams struct {
	Path string `mapstructure:"list"`
}

type InvalidRuleNameError

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

func (InvalidRuleNameError) Error

func (e InvalidRuleNameError) Error() string

type MallebaleRule

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

func (*MallebaleRule) Apply

func (f *MallebaleRule) Apply(
	e wrapper.Entity,
	logger zerolog.Logger,
) (bool, error)

func (*MallebaleRule) Prepare

func (f *MallebaleRule) Prepare(
	_ wrapper.Entity,
	_ zerolog.Logger,
) error

func (*MallebaleRule) String

func (f *MallebaleRule) String() string

type MallebaleRuleParams

type MallebaleRuleParams struct {
	Profile string   `mapstructure:"profile"`
	Exclude []string `mapstructure:"exclude"`
}

type RegexpParams

type RegexpParams struct {
	Path string `mapstructure:"list"`
}

type RegexpRule

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

func (RegexpRule) Apply

func (f RegexpRule) Apply(
	e wrapper.Entity,
	logger zerolog.Logger,
) (bool, error)

func (*RegexpRule) Prepare

func (f *RegexpRule) Prepare(
	_ wrapper.Entity,
	_ zerolog.Logger,
) error

func (RegexpRule) String

func (f RegexpRule) String() string

type ReverseLookupParams

type ReverseLookupParams struct {
	DNS  string `mapstructure:"dns"`
	Path string `mapstructure:"list"`
}

type ReverseLookupRule

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

func (*ReverseLookupRule) Apply

func (f *ReverseLookupRule) Apply(
	e wrapper.Entity,
	logger zerolog.Logger,
) (bool, error)

func (*ReverseLookupRule) Prepare

func (f *ReverseLookupRule) Prepare(
	e wrapper.Entity,
	logger zerolog.Logger,
) error

func (*ReverseLookupRule) String

func (f *ReverseLookupRule) String() string

type Rule

type Rule interface {
	Prepare(wrapper.Entity, zerolog.Logger) error
	Apply(wrapper.Entity, zerolog.Logger) (bool, error)
	fmt.Stringer
}

func NewCompositeAndRule

func NewCompositeAndRule(
	_ *database.DB,
	rs RuleSet,
	cfg common.RuleConfig,
	_ common.Globals,
) (Rule, error)

func NewCompositeNotRule

func NewCompositeNotRule(
	_ *database.DB,
	rs RuleSet,
	cfg common.RuleConfig,
	_ common.Globals,
) (Rule, error)

func NewCompositeOrRule

func NewCompositeOrRule(
	_ *database.DB,
	rs RuleSet,
	cfg common.RuleConfig,
	_ common.Globals,
) (Rule, error)

func NewGeolocationRule

func NewGeolocationRule(
	db *database.DB,
	_ RuleSet,
	cfg common.RuleConfig,
	gloals common.Globals,
) (Rule, error)

func NewIPRule

func NewIPRule(
	_ *database.DB,
	_ RuleSet,
	cfg common.RuleConfig,
	_ common.Globals,
) (Rule, error)

func NewMalleableRule

func NewMalleableRule(
	_ *database.DB,
	_ RuleSet,
	cfg common.RuleConfig,
	_ common.Globals,
) (Rule, error)

TODO: add unit tests for malleable rule.

func NewNotWrapper

func NewNotWrapper(r Rule, _ common.RuleConfig) Rule

func NewRegexpRule

func NewRegexpRule(
	_ *database.DB,
	_ RuleSet,
	cfg common.RuleConfig,
	_ common.Globals,
) (Rule, error)

func NewReverseLookupRule

func NewReverseLookupRule(
	db *database.DB,
	_ RuleSet,
	cfg common.RuleConfig,
	_ common.Globals,
) (Rule, error)

func NewTimeRule

func NewTimeRule(
	_ *database.DB,
	_ RuleSet,
	cfg common.RuleConfig,
	_ common.Globals,
) (Rule, error)

type RuleBaseCreator

type RuleBaseCreator func(
	db *database.DB,
	rs RuleSet,
	cfg common.RuleConfig,
	globals common.Globals,
) (Rule, error)

type RuleSet

type RuleSet struct {
	Rules map[string]Rule
}

func NewRuleSet

func NewRuleSet(
	db *database.DB,
	cfg []common.RuleConfig,
	globals common.Globals,
) (*RuleSet, error)

func (*RuleSet) Get

func (rs *RuleSet) Get(name string) (Rule, bool)

type RuleWrapperCreator

type RuleWrapperCreator func(
	rule Rule,
	cfg common.RuleConfig,
) Rule

type TimeParams

type TimeParams struct {
	From     string   `mapstructure:"from"`
	To       string   `mapstructure:"to"`
	Location string   `mapstructure:"timezone"`
	Weekdays []string `mapstructure:"weekdays"`
}

type TimeRule

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

func (*TimeRule) Apply

func (f *TimeRule) Apply(
	_ wrapper.Entity,
	logger zerolog.Logger,
) (bool, error)

func (*TimeRule) Prepare

func (f *TimeRule) Prepare(
	_ wrapper.Entity,
	_ zerolog.Logger,
) error

func (*TimeRule) String

func (f *TimeRule) String() string

type UnknownBaseRuleError

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

func (UnknownBaseRuleError) Error

func (e UnknownBaseRuleError) Error() string

type UnknownDayOfWeekError

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

func (UnknownDayOfWeekError) Error

func (e UnknownDayOfWeekError) Error() string

type UnknownTransformError

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

func (UnknownTransformError) Error

func (e UnknownTransformError) Error() string

type UnknownWrapperRuleError

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

func (UnknownWrapperRuleError) Error

func (e UnknownWrapperRuleError) Error() string

Jump to

Keyboard shortcuts

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