rules

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RuleAny denotes any rule type
	RuleAny = iota

	// RuleRoute denotes rules with a routing field
	RuleRoute

	// RuleAction denotes rules with an action field
	RuleAction
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	IV      string `json:"IV"`
	Payload string `json:"payload"`
}

Entry is used to encapsulate a record with an IV for encryption and decryption.

type Filter

type Filter struct {
	// IDs is the set of acceptable rule IDs. A rule will pass the filter if its ID is a member of this set.
	// This field is ignored when len(IDs) <= 0.
	IDs []string

	// Tags is the set of tags each rule must contain. A rule will pass the filter if its tags are a subset of this
	// set. This field is ignored when len(Tags) <= 0.
	Tags []string

	// Destinations is the set of acceptable rule destinations. A rule will pass the filter if its destination is
	// a member of this set. This field is ignored when len(Destinations) <= 0.
	Destinations []string

	// RuleType is the type of rule to filter by.
	RuleType int
}

Filter to apply to sets of rules.

func (Filter) Empty

func (f Filter) Empty() bool

Empty returns whether the filter has any attributes that would cause rules to be filtered out. A filter is considered empty if no rules would be filtered out from any set of rules.

func (Filter) String

func (f Filter) String() string

String representation of the filter

type InvalidRuleError

type InvalidRuleError struct{}

InvalidRuleError occurs when a rule is not valid

func (*InvalidRuleError) Error

func (e *InvalidRuleError) Error() string

Error description

type JSONMarshalError

type JSONMarshalError struct {
	Message string
}

JSONMarshalError describes a JSON marshal or unmarshaling error

func (*JSONMarshalError) Error

func (e *JSONMarshalError) Error() string

Error description

type Manager

type Manager interface {
	// AddRules validates the rules and adds them to the collection for the namespace.
	AddRules(namespace string, rules []Rule) (NewRules, error)

	// GetRules returns a collection of filtered rules from the namespace.
	GetRules(namespace string, filter Filter) (RetrievedRules, error)

	// UpdateRules updates rules by ID in the namespace.
	UpdateRules(namespace string, rules []Rule) error

	// DeleteRules deletes rules that match the filter in the namespace.
	DeleteRules(namespace string, filter Filter) error

	// SetRules deletes the rules that match the filter and adds the new rules as a single
	// atomic transaction.
	SetRules(namespace string, filter Filter, rules []Rule) (NewRules, error)
}

Manager is an interface for managing collections of rules mapped by namespace.

func NewMemoryManager

func NewMemoryManager(validator Validator) Manager

NewMemoryManager constructs a new in memory manager.

func NewRedisManager

func NewRedisManager(host, pass string, v Validator) Manager

NewRedisManager creates a Redis backed manager implementation.

type NewRules

type NewRules struct {
	// IDs of the added rules.
	IDs []string
}

NewRules provides information about newly added rules.

type RedisInsertError

type RedisInsertError struct{}

RedisInsertError occurs when there is an issue writing to Redis

func (*RedisInsertError) Error

func (e *RedisInsertError) Error() string

Error description

type RetrievedRules

type RetrievedRules struct {
	// Rules that passed the filter.
	Rules []Rule

	// Revision of the rules for this namespace. Each time the collection of rules for the namespace are changed
	// the revision is incremented.
	Revision int64
}

RetrievedRules are the results of a read from a manager.

type Rule

type Rule struct {
	ID          string          `json:"id"`
	Priority    int             `json:"priority"`
	Tags        []string        `json:"tags,omitempty"`
	Destination string          `json:"destination"`
	Match       json.RawMessage `json:"match,omitempty"`
	Route       json.RawMessage `json:"route,omitempty"`
	Actions     json.RawMessage `json:"actions,omitempty"`
}

Rule represents an individual rule.

func FilterRules

func FilterRules(f Filter, rules []Rule) []Rule

FilterRules returns a list of filtered rules.

type Validator

type Validator interface {
	Validate(Rule) error
}

Validator validates rules against the rule schema.

func NewValidator

func NewValidator() (Validator, error)

NewValidator returns a new Validator.

Jump to

Keyboard shortcuts

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