builder

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterActionBuilder

func RegisterActionBuilder(pclass, aclass string, builder BuildActionFn)

RegisterActionBuilder registers an action builder for class

func RegisterPluginBuilder

func RegisterPluginBuilder(class string, builder BuildPluginFn)

RegisterPluginBuilder registers a plugin builder for class

Types

type ActionDef

type ActionDef struct {
	// Name must exist and be unique in databases for its correct operation
	Name string `json:"name"`
	// Class defines the class
	Class string `json:"class"`
	// Disabled
	Disabled bool `json:"disabled"`
	// Services is a map of services used by plugin
	Services map[string]string `json:"services,omitempty"`
	// Rules is a list of ruleset definitions
	Rules []RuleItemDef `json:"rules,omitempty"`
	// OnError stores on error verdict
	OnError string `json:"onerror,omitempty"`
	// Opts allow optional fields
	Opts map[string]interface{} `json:"opts,omitempty"`
}

ActionDef is used for construct actions

type BuildActionFn

type BuildActionFn func(b *Builder, pname string, def ActionDef) (nfqueue.Action, error)

BuildActionFn defines a function that constructs an action using a definition

type BuildPluginFn

type BuildPluginFn func(b *Builder, def PluginDef) (nfqueue.Plugin, error)

BuildPluginFn defines a function that constructs a plugin

type Builder

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

Builder constructs plugins and actions using definitions

func New

func New(services apiservice.Discover, opt ...Option) *Builder

New creates a new builder

func (Builder) APIService

func (b Builder) APIService(name string) (apiservice.Service, bool)

APIService returns service by name

func (*Builder) AddLocalNet

func (b *Builder) AddLocalNet(s string) error

AddLocalNet add a local net to builder

func (*Builder) BuildAction

func (b *Builder) BuildAction(pname, pclass string, def ActionDef) (nfqueue.Action, error)

BuildAction creates an action using the plugin name, class and metadata passed as param

func (*Builder) BuildPlugin

func (b *Builder) BuildPlugin(def PluginDef) (nfqueue.Plugin, error)

BuildPlugin creates a plugin using the metadata passed as param

func (Builder) CachePath

func (b Builder) CachePath(data string) string

CachePath returns path for cache

func (*Builder) CleanUp

func (b *Builder) CleanUp()

CleanUp all created plugins

func (Builder) DataPath

func (b Builder) DataPath(data string) string

DataPath returns path for data

func (Builder) LocalNets

func (b Builder) LocalNets() []*net.IPNet

LocalNets return localnets

func (Builder) Logger

func (b Builder) Logger() yalogi.Logger

Logger returns logger

func (*Builder) OnShutdown

func (b *Builder) OnShutdown(f func() error)

OnShutdown registers the functions that will be executed during shutdown.

func (*Builder) OnStartup

func (b *Builder) OnStartup(f func() error)

OnStartup registers the functions that will be executed during startup.

func (*Builder) Plugin

func (b *Builder) Plugin(name string) (nfqueue.Plugin, bool)

Plugin returns plugin by name

func (*Builder) Plugins

func (b *Builder) Plugins() []nfqueue.Plugin

Plugins returns plugins builded

func (*Builder) Shutdown

func (b *Builder) Shutdown() error

Shutdown executes all registered functions.

func (*Builder) Start

func (b *Builder) Start() error

Start executes all registered functions.

type Option

type Option func(*options)

Option is used for builder configuration

func CacheDir

func CacheDir(s string) Option

CacheDir sets source dir

func DataDir

func DataDir(s string) Option

DataDir sets data dir

func SetLogger

func SetLogger(l yalogi.Logger) Option

SetLogger sets a logger for the component

type PluginDef

type PluginDef struct {
	// Name must exist and be unique in databases for its correct operation
	Name string `json:"name"`
	// Class defines the class
	Class string `json:"class"`
	// Disabled
	Disabled bool `json:"disabled"`
	// Services is a map of services used by plugin
	Services map[string]string `json:"services,omitempty"`
	// Actions is a list of actions
	Actions []ActionDef `json:"actions,omitempty"`
	// Opts allow optional fields
	Opts map[string]interface{} `json:"opts,omitempty"`
}

PluginDef is used for construct plugins

func PluginDefsFromFile

func PluginDefsFromFile(path string) ([]PluginDef, error)

PluginDefsFromFile creates a slice of PluginDef from a file in json format.

type RuleDef

type RuleDef struct {
	// Merge option
	Merge bool `json:"merge,omitempty"`
	// Event stores event level
	Event string `json:"event,omitempty"`
	// Log enable logging in action
	Log bool `json:"log"`
	// Verdict stores verdict to firewall processors
	Verdict string `json:"verdict,omitempty"`
}

RuleDef stores information about rules

type RuleItemDef

type RuleItemDef struct {
	// When defines condition
	When string `json:"when"`
	// Rule stores definition
	Rule RuleDef `json:"rule"`
}

RuleItemDef defines a set of rules

Jump to

Keyboard shortcuts

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