act

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: Apache-2.0 Imports: 6 Imported by: 5

Documentation

Index

Constants

View Source
const (
	Signals  = "__signals__"
	Outputs  = "__outputs__"
	Terminal = "__terminal__"
	Name     = "name"
	Metadata = "metadata"
	Sync     = "sync"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Name     string         `json:"name"`
	Metadata map[string]any `json:"metadata"`
	Sync     bool           `json:"sync"`
	Terminal bool           `json:"terminal"`
	Timeout  int            `json:"timeout"`
	Run      ActionFunc     `json:"-"`
}

Action is any action that can be performed by the system.

type ActionFunc

type ActionFunc func(data map[string]any, params ...Parameter) (any, error)

ActionFunc is a function that can be used to run an action. Optionally, it can receive parameters like a logger, a database connection, or any other data that the action needs to run.

type Consumer added in v0.2.15

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

func NewConsumer added in v0.2.15

func NewConsumer(
	logger hclog.Logger, redisClient *redis.Client, workersCount int, channelName string,
) (*Consumer, error)

func (*Consumer) Subscribe added in v0.2.15

func (c *Consumer) Subscribe(ctx context.Context, handler MessageHandlerFn) error

type Hook added in v0.2.14

type Hook struct {
	Name     string         `json:"name"`
	Priority uint           `json:"priority"`
	Params   map[string]any `json:"params"`
	Result   map[string]any `json:"result"`
}

type IConsumer added in v0.2.15

type IConsumer interface {
	Subscribe(ctx context.Context, handler MessageHandlerFn) error
}

type IPolicy

type IPolicy interface {
	MustCompile(opts ...expr.Option) error
	Eval(ctx context.Context, input Input) (any, error)
}

type Input

type Input struct {
	Name   string         `json:"name"`
	Policy map[string]any `json:"policy"`
	Signal map[string]any `json:"signal"`
	Hook   Hook           `json:"hook"`
	Sync   bool           `json:"sync"`
}

type MessageHandlerFn added in v0.2.15

type MessageHandlerFn func(ctx context.Context, payload []byte) error

type Output

type Output struct {
	MatchedPolicy string         `json:"matchedPolicy"`
	Metadata      map[string]any `json:"metadata"`
	Verdict       any            `json:"verdict"`
	Terminal      bool           `json:"terminal"`
	Sync          bool           `json:"sync"`
}

type Parameter added in v0.2.2

type Parameter struct {
	Key   string
	Value any
}

Parameter is a parameter that can be passed to an action by the system (runner), like a logger, a database connection, or any other data.

type Policy

type Policy struct {
	Name     string         `json:"name"`
	Policy   string         `json:"policy"`
	Metadata map[string]any `json:"metadata"`
	// contains filtered or unexported fields
}

func MustNewPolicy

func MustNewPolicy(
	name string, policy string, metadata map[string]any, opts ...expr.Option,
) *Policy

func NewPolicy

func NewPolicy(
	name string, policy string, metadata map[string]any, opts ...expr.Option,
) (*Policy, error)

func (*Policy) Eval

func (p *Policy) Eval(ctx context.Context, input Input) (any, error)

func (*Policy) MustCompile

func (p *Policy) MustCompile(extraOpts ...expr.Option) error

type Signal

type Signal struct {
	Name     string         `json:"name"`
	Metadata map[string]any `json:"metadata"`
}

func Log added in v0.2.1

func Log(level, message string, fields map[string]any) *Signal

func Passthrough added in v0.2.3

func Passthrough() *Signal

func Terminate added in v0.2.1

func Terminate() *Signal

func (*Signal) ToMap

func (s *Signal) ToMap() map[string]any

Jump to

Keyboard shortcuts

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