act

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TerminateDefaultParamCount is the default parameter count for the terminate action.
	TerminateDefaultParamCount = 2

	// LogDefaultKeyCount is the default key count in the metadata for the log action.
	LogDefaultKeyCount = 3

	// These are the keys used to pass the logger and the result to the built-in actions.
	LoggerKey = "__logger__"
	ResultKey = "__result__"
)

Variables

This section is empty.

Functions

func BuiltinActions

func BuiltinActions() map[string]*sdkAct.Action

BuiltinActions returns a map of built-in actions.

func BuiltinPolicies

func BuiltinPolicies() map[string]*sdkAct.Policy

BuiltinPolicies returns a map of built-in policies.

func BuiltinSignals

func BuiltinSignals() map[string]*sdkAct.Signal

BuiltinSignals returns a map of built-in signals.

func Log

func Log(data map[string]any, params ...sdkAct.Parameter) (any, error)

Log is a built-in action that logs the data received from the plugin.

func Passthrough

func Passthrough(map[string]any, ...sdkAct.Parameter) (any, error)

Passthrough is a built-in action that always returns true and no error.

func Terminate

func Terminate(_ map[string]any, params ...sdkAct.Parameter) (any, error)

Terminate is a built-in action that terminates the connection if the terminate signal is true and the policy is set to "stop". The action can optionally receive a result parameter.

func WithLogger

func WithLogger(logger zerolog.Logger) sdkAct.Parameter

WithLogger returns a parameter with the logger to be used by the action. This is automatically prepended to the parameters when running an action.

func WithResult

func WithResult(result map[string]any) sdkAct.Parameter

WithResult returns a parameter with the result of the plugin hook to be used by the action.

Types

type IRegistry

type IRegistry interface {
	Add(policy *sdkAct.Policy)
	Apply(signals []sdkAct.Signal) []*sdkAct.Output
	Run(output *sdkAct.Output, params ...sdkAct.Parameter) (any, *gerr.GatewayDError)
}

type Registry

type Registry struct {
	Logger zerolog.Logger
	// Timeout for policy evaluation.
	PolicyTimeout time.Duration
	// Default timeout for running actions
	DefaultActionTimeout time.Duration

	Signals           map[string]*sdkAct.Signal
	Policies          map[string]*sdkAct.Policy
	Actions           map[string]*sdkAct.Action
	DefaultPolicyName string
	DefaultPolicy     *sdkAct.Policy
	DefaultSignal     *sdkAct.Signal
}

Registry keeps track of all policies and actions.

func NewActRegistry

func NewActRegistry(
	registry Registry,
) *Registry

NewActRegistry creates a new act registry with the specified default policy and timeout and the builtin signals, policies, and actions.

func (*Registry) Add

func (r *Registry) Add(policy *sdkAct.Policy)

Add adds a policy to the registry.

func (*Registry) Apply

func (r *Registry) Apply(signals []sdkAct.Signal) []*sdkAct.Output

Apply applies the signals to the registry and returns the outputs.

func (*Registry) Run

func (r *Registry) Run(
	output *sdkAct.Output, params ...sdkAct.Parameter,
) (any, *gerr.GatewayDError)

Run runs the function associated with the output.MatchedPolicy and returns its result. If the action is synchronous, the result is returned immediately. If the action is asynchronous, the result is nil and the error is ErrAsyncAction, which is a sentinel error to indicate that the action is running asynchronously.

Jump to

Keyboard shortcuts

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