policy

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package policy implements server-enforced API-key spending admissions.

Index

Constants

This section is empty.

Variables

View Source
var ErrApprovalRequired = errors.New("transaction requires an independent approval decision")
View Source
var ErrDenied = errors.New("spending policy denied transaction")
View Source
var ErrIdentityConflict = errors.New("policy idempotency identity already has different transaction details")

Functions

func Allowed

func Allowed(list []string, id string) bool

func Apply

func Apply(a *model.PolicyAdmission, t *model.Transaction)

func Integer

func Integer(s string) (*big.Int, error)

func Internal

func Internal(ctx context.Context) context.Context

Internal marks an already-admitted fan-out, never a caller assertion.

func Intersect

func Intersect(key string, policies []model.KeyPolicy) *model.KeyPolicy

Intersect keeps only currencies and destinations permitted by every ancestor. Empty configured allowlists mean unrestricted; an empty intersection denies all.

func IsInternal

func IsInternal(ctx context.Context) bool

func RuleKey

func RuleKey(currency string, precision float64) string

func Validate

func Validate(p model.KeyPolicy) error

func ValidateNarrowing

func ValidateNarrowing(child model.KeyPolicy, parent *model.KeyPolicy) error

ValidateNarrowing rejects a local child policy that claims any permission broader than its ancestors. An absent child policy inherits them unchanged.

func WithPrincipal

func WithPrincipal(ctx context.Context, p Principal) context.Context

WithPrincipal is called only by trusted authentication adapters.

Types

type Engine

type Engine struct{ Store Store }

func (Engine) Admit

func (e Engine) Admit(ctx context.Context, identity string, legs []model.PolicyLeg) (*model.PolicyAdmission, error)

type Principal

type Principal struct {
	APIKeyID string
	Master   bool
	Scopes   []string
}

func FromContext

func FromContext(ctx context.Context) Principal

func (Principal) CanApprove

func (p Principal) CanApprove() bool

func (Principal) CanManagePolicies

func (p Principal) CanManagePolicies() bool

type Store

type Store interface {
	GetKeyPolicy(context.Context, string) (*model.KeyPolicy, error)
	PutKeyPolicy(context.Context, model.KeyPolicy) (*model.KeyPolicy, error)
	DeleteKeyPolicy(context.Context, string) error
	AdmitPolicy(context.Context, string, string, []model.PolicyLeg) (*model.PolicyAdmission, error)
	VerifyPolicyLeg(context.Context, *model.Transaction) (*model.PolicyAdmission, error)
	CheckPolicyCommit(context.Context, string) error
	ReleasePolicyLeg(context.Context, string) error
	ListPolicyApprovals(context.Context, string) ([]model.PolicyAdmission, error)
	DecidePolicyApproval(context.Context, string, Principal, bool) (*model.PolicyAdmission, error)
	PolicyCapacity(context.Context, string) ([]model.PolicyCapacity, error)
	PolicyHoldIDs(context.Context, string) ([]string, error)
}

Jump to

Keyboard shortcuts

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