action

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package action decodes the actions a policy returns. A policy's result is {"actions": [...]}, and each action is a name such as "signup.allow", or an object with an "action" name and the action's parameters:

{"actions": ["signup.allow", {"action": "signup.deny", "reason": "..."}]}

Names are "<resource>.<verb>". Each hook decides which actions it accepts, what they mean together, and in which order they run.

Index

Constants

This section is empty.

Variables

View Source
var ErrV0Result = errors.New(`policy result uses the v0 shape ({"action": ...}): return {"actions": [...]} instead (see docs/upgrading-to-v1.md)`)

ErrV0Result is returned for a result in the v0 shape.

Functions

func Unknown

func Unknown(a Action, hook string, known []string) error

Unknown returns an error for an action the hook doesn't accept.

Types

type Action

type Action struct {
	// Name is the action's name, lowercased, such as "signup.deny".
	Name string
	// contains filtered or unexported fields
}

Action is one action from a policy result.

func (Action) Decode

func (a Action) Decode(v any) error

Decode decodes the action's parameters into v, a pointer to a struct. Unknown parameters are errors, so a misspelled one isn't ignored; pass a pointer to an empty struct for an action that takes none.

func (Action) MarshalJSON

func (a Action) MarshalJSON() ([]byte, error)

MarshalJSON writes the action the way the policy returned it.

func (*Action) UnmarshalJSON

func (a *Action) UnmarshalJSON(b []byte) error

UnmarshalJSON accepts a name or an object with an "action" name.

type Result

type Result struct {
	Actions []Action `json:"actions"`
	// V0Action is the top-level "action" of v0 results, decoded only to
	// report a helpful error.
	V0Action json.RawMessage `json:"action,omitempty"`
}

Result is a policy's result document.

func (Result) Check

func (r Result) Check() error

Check reports a result in the v0 shape.

Jump to

Keyboard shortcuts

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