modconfig

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package modconfig provides matchers for config.Map that query modules registry and parse inline module definitions.

They should be used instead of manual querying when there is need to reference a module instance in the configuration.

See ModuleFromNode documentation for explanation of what is 'args' for some functions (DeliveryTarget).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeliveryDirective

func DeliveryDirective(m *config.Map, node config.Node) (interface{}, error)

DeliveryDirective is a callback for use in config.Map.Custom.

It does all work necessary to create a module instance from the config directive with the following structure:

directive_name mod_name [inst_name] [{
  inline_mod_config
}]

Note that if used configuration structure lacks directive_name before mod_name - this function should not be used (call DeliveryTarget directly).

func DeliveryTarget

func DeliveryTarget(globals map[string]interface{}, args []string, block config.Node) (module.DeliveryTarget, error)

func FailActionDirective

func FailActionDirective(_ *config.Map, node config.Node) (interface{}, error)

func GroupFromNode

func GroupFromNode(defaultModule string, args []string, inlineCfg config.Node, globals map[string]interface{}, moduleIface interface{}) error

GroupFromNode provides a special kind of ModuleFromNode syntax that allows to omit the module name when defining inine configuration. If it is not present, name in defaultModule is used.

func IMAPFilter

func IMAPFilter(globals map[string]interface{}, args []string, block config.Node) (module.IMAPFilter, error)

func MessageCheck

func MessageCheck(globals map[string]interface{}, args []string, block config.Node) (module.Check, error)

func ModuleFromNode

func ModuleFromNode(preferredNamespace string, args []string, inlineCfg config.Node, globals map[string]interface{}, moduleIface interface{}) error

ModuleFromNode does all work to create or get existing module object with a certain type. It is not used by top-level module definitions, only for references from other modules configuration blocks.

inlineCfg should contain configuration directives for inline declarations. args should contain values that are used to create module. It should be either module name + instance name or just module name. Further extensions may add other string arguments (currently, they can be accessed by module instances as inlineArgs argument to constructor).

It checks using reflection whether it is possible to store a module object into modObj pointer (e.g. it implements all necessary interfaces) and stores it if everything is fine. If module object doesn't implement necessary module interfaces - error is returned. If modObj is not a pointer, ModuleFromNode panics.

preferredNamespace is used as an implicit prefix for module name lookups. Module with name preferredNamespace + "." + args[0] will be preferred over just args[0]. It can be omitted.

func MsgModifier

func MsgModifier(globals map[string]interface{}, args []string, block config.Node) (module.Modifier, error)

func ParseRejectDirective

func ParseRejectDirective(args []string) (*exterrors.SMTPError, error)

func StorageDirective

func StorageDirective(m *config.Map, node config.Node) (interface{}, error)

func Table added in v0.7.0

func Table(cfg *config.Map, name string, inheritGlobal, required bool, defaultVal module.Table, store *module.Table)

Table is a convenience wrapper for TableDirective.

cfg.Bool(...)
modconfig.Table(cfg, "auth_map", false, false, nil, &mod.authMap)
cfg.Process()

func TableDirective

func TableDirective(m *config.Map, node config.Node) (interface{}, error)

Types

type FailAction

type FailAction struct {
	Quarantine bool
	Reject     bool

	ReasonOverride *exterrors.SMTPError
}

FailAction specifies actions that messages pipeline should take based on the result of the check.

Its check module responsibility to apply FailAction on the CheckResult it returns. It is intended to be used as follows:

Add the configuration directive to allow user to specify the action:

cfg.Custom("SOME_action", false, false,
	func() (interface{}, error) {
		return modconfig.FailAction{Quarantine: true}, nil
	}, modconfig.FailActionDirective, &yourModule.SOMEAction)

return in func literal is the default value, you might want to adjust it.

Call yourModule.SOMEAction.Apply on CheckResult containing only the Reason field:

func (yourModule YourModule) CheckConnection() module.CheckResult {
    return yourModule.SOMEAction.Apply(module.CheckResult{
        Reason: ...,
    })
}

func ParseActionDirective

func ParseActionDirective(args []string) (FailAction, error)

func (FailAction) Apply

func (cfa FailAction) Apply(originalRes module.CheckResult) module.CheckResult

Apply merges the result of check execution with action configuration specified in the check configuration.

Jump to

Keyboard shortcuts

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