policy

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: Apache-2.0 Imports: 2 Imported by: 3

Documentation

Overview

Package policy provides optional declarative rules that can be applied on top of a running Fluxor engine – for example to require human approval for selected tasks or to enforce execution constraints.

Index

Constants

View Source
const (
	ModeAsk  = "ask"  // ask user before every action
	ModeAuto = "auto" // execute automatically (default)
	ModeDeny = "deny" // block execution
)

Execution modes recognised by the engine.

Variables

This section is empty.

Functions

func WithPolicy

func WithPolicy(ctx context.Context, p *Policy) context.Context

WithPolicy embeds policy in ctx.

Types

type AskFunc

type AskFunc func(
	ctx context.Context,
	action string,
	args map[string]interface{},
	p *Policy,
) bool

AskFunc is invoked when Mode==ask. Returning true approves the action, false rejects it. Implementations MAY mutate the policy (for example, switching to ModeAuto after the first approval).

type Config

type Config struct {
	Mode      string   `json:"mode,omitempty" yaml:"mode,omitempty"`
	AllowList []string `json:"allow,omitempty" yaml:"allow,omitempty"`
	BlockList []string `json:"block,omitempty" yaml:"block,omitempty"`
}

Config represents the declarative, serialisable part of a Policy.

func ToConfig

func ToConfig(p *Policy) *Config

ToConfig converts a runtime Policy into a persistable Config.

type Policy

type Policy struct {
	Mode      string   // ask / auto / deny      (default = auto)
	AllowList []string // whitelist (empty => all)
	BlockList []string // blacklist
	Ask       AskFunc  // used only when Mode==ask
}

Policy represents the approval / debugging settings for the current workflow-run.

  • Mode controls the high-level behaviour (ask / auto / deny).
  • AllowList, BlockList allow coarse filtering regardless of Mode.
  • Ask is only used when Mode==ask.

A nil *Policy means "execute everything automatically" and is therefore the zero-cost default.

func FromConfig

func FromConfig(c *Config) *Policy

FromConfig converts a stored Config back to a runtime Policy (without AskFunc).

func FromContext

func FromContext(ctx context.Context) *Policy

FromContext extracts (*Policy, ok).

func (*Policy) IsAllowed

func (p *Policy) IsAllowed(action string) bool

IsAllowed evaluates AllowList / BlockList. Both lists match by exact string comparison (case-insensitive) of the fully-qualified action name "service.method".

Jump to

Keyboard shortcuts

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