actions

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 19 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBoolArg added in v0.6.9

func GetBoolArg(args *structpb.Struct, key string) (bool, bool)

GetBoolArg extracts a bool value from the args struct by key. Returns the value and true if found, false and false otherwise.

func GetEntitlementListFieldArg added in v0.7.9

func GetEntitlementListFieldArg(args *structpb.Struct, key string) ([]*v2.Entitlement, bool)

GetEntitlementListFieldArg extracts a list of Entitlement proto messages from the args struct by key. Each Entitlement is expected to be stored as a JSON-serialized struct value. Returns the list of Entitlement and true if found and valid, or nil and false otherwise.

func GetGrantListFieldArg added in v0.7.9

func GetGrantListFieldArg(args *structpb.Struct, key string) ([]*v2.Grant, bool)

GetGrantListFieldArg extracts a list of Grant proto messages from the args struct by key. Each Grant is expected to be stored as a JSON-serialized struct value. Returns the list of Grant and true if found and valid, or nil and false otherwise.

func GetIntArg added in v0.6.9

func GetIntArg(args *structpb.Struct, key string) (int64, bool)

GetIntArg extracts an int64 value from the args struct by key. Returns the value and true if found, 0 and false otherwise.

func GetResourceFieldArg added in v0.6.9

func GetResourceFieldArg(args *structpb.Struct, key string) (*v2.Resource, bool)

GetResourceFieldArg extracts a Resource proto message from the args struct by key. The Resource is expected to be stored as a JSON-serialized struct value. Returns the Resource and true if found and valid, or nil and false otherwise.

func GetResourceIDArg added in v0.6.9

func GetResourceIDArg(args *structpb.Struct, key string) (*v2.ResourceId, bool)

GetResourceIDArg extracts a ResourceId from the args struct by key. The value is expected to be a struct with "resource_type_id" and "resource_id" fields (as stored by ResourceField). Returns the ResourceId and true if found, nil and false otherwise.

func GetResourceIdListArg added in v0.6.9

func GetResourceIdListArg(args *structpb.Struct, key string) ([]*v2.ResourceId, bool)

GetResourceIdListArg extracts a list of ResourceId from the args struct by key. Returns the list and true if found and valid, or nil and false otherwise.

func GetResourceListFieldArg added in v0.6.9

func GetResourceListFieldArg(args *structpb.Struct, key string) ([]*v2.Resource, bool)

GetResourceListFieldArg extracts a list of Resource proto messages from the args struct by key. Each Resource is expected to be stored as a JSON-serialized struct value. Returns the list of Resource and true if found and valid, or nil and false otherwise.

func GetStringArg added in v0.6.9

func GetStringArg(args *structpb.Struct, key string) (string, bool)

GetStringArg extracts a string value from the args struct by key. Returns the value and true if found, empty string and false otherwise.

func GetStringSliceArg added in v0.6.9

func GetStringSliceArg(args *structpb.Struct, key string) ([]string, bool)

GetStringSliceArg extracts a string slice from the args struct by key. Returns the slice and true if found, nil and false otherwise.

func GetStructArg added in v0.6.9

func GetStructArg(args *structpb.Struct, key string) (*structpb.Struct, bool)

GetStructArg extracts a nested struct from the args struct by key. Returns the struct and true if found, nil and false otherwise.

func IsInFlight added in v0.24.2

func IsInFlight(s v2.BatonActionStatus) bool

IsInFlight reports whether the status describes an action still executing: PENDING or RUNNING.

func IsSettled added in v0.24.2

func IsSettled(s v2.BatonActionStatus) bool

IsSettled reports whether the status is terminal: COMPLETE or FAILED. It is the single gate deciding which statuses are final; a new terminal enum value must be added here to be treated as settled anywhere.

func NewReturnValues added in v0.6.9

func NewReturnValues(success bool, fields ...ReturnField) *structpb.Struct

NewReturnValues creates a return struct with the specified success status and fields. This helps users avoid having to remember the correct structure for return values.

func RequireResourceIDArg added in v0.6.9

func RequireResourceIDArg(args *structpb.Struct, key string) (*v2.ResourceId, error)

RequireResourceIDArg extracts a ResourceId from the args struct by key. Returns the ResourceId or an error if not found or invalid.

func RequireResourceIdListArg added in v0.6.9

func RequireResourceIdListArg(args *structpb.Struct, key string) ([]*v2.ResourceId, error)

RequireResourceIdListArg extracts a list of ResourceId from the args struct by key. Returns the list of ResourceId or an error if not found or invalid.

func RequireStringArg added in v0.6.9

func RequireStringArg(args *structpb.Struct, key string) (string, error)

RequireStringArg extracts a string value from the args struct by key. Returns the value or an error if not found or invalid.

func SetResourceFieldArg added in v0.6.9

func SetResourceFieldArg(args *structpb.Struct, key string, resource *v2.Resource) error

SetResourceFieldArg stores a Resource proto message in the args struct by key. The Resource is serialized as a JSON struct value.

Types

type ActionHandler

type ActionHandler func(ctx context.Context, args *structpb.Struct) (*structpb.Struct, annotations.Annotations, error)

type ActionManager

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

ActionManager manages both global actions and resource-scoped actions.

func NewActionManager

func NewActionManager(_ context.Context) *ActionManager

func (*ActionManager) CleanupOldActions

func (a *ActionManager) CleanupOldActions(ctx context.Context)

func (*ActionManager) GetActionSchema

func (*ActionManager) GetActionStatus

func (*ActionManager) GetNewAction

func (a *ActionManager) GetNewAction(name string) *OutstandingAction

func (*ActionManager) GetNewActionId

func (a *ActionManager) GetNewActionId() string

func (*ActionManager) GetTypeRegistry added in v0.6.9

func (a *ActionManager) GetTypeRegistry(_ context.Context, resourceTypeID string) (ActionRegistry, error)

GetTypeRegistry returns an ActionRegistry for registering actions scoped to a specific resource type.

func (*ActionManager) HasActions added in v0.6.9

func (a *ActionManager) HasActions() bool

func (*ActionManager) InvokeAction

func (a *ActionManager) InvokeAction(
	ctx context.Context,
	name string,
	resourceTypeID string,
	args *structpb.Struct,
) (string, v2.BatonActionStatus, *structpb.Struct, annotations.Annotations, error)

InvokeAction invokes an action. If resourceTypeID is set, it invokes a resource-scoped action. Otherwise, it invokes a global action.

func (*ActionManager) InvokeActionWithWait added in v0.24.0

func (a *ActionManager) InvokeActionWithWait(
	ctx context.Context,
	name string,
	resourceTypeID string,
	args *structpb.Struct,
	inlineWait time.Duration,
) (string, v2.BatonActionStatus, *structpb.Struct, annotations.Annotations, error)

InvokeActionWithWait is InvokeAction with an explicit bound on how long the call may block waiting for the handler before returning the action's in-flight status; zero or negative keeps the default.

func (*ActionManager) ListActionSchemas

func (a *ActionManager) ListActionSchemas(_ context.Context, resourceTypeID string) ([]*v2.BatonActionSchema, annotations.Annotations, error)

ListActionSchemas returns all action schemas, optionally filtered by resource type. If resourceTypeID is empty, returns all global actions plus all resource-scoped actions. If resourceTypeID is set, returns only actions for that resource type.

func (*ActionManager) Register added in v0.6.9

func (a *ActionManager) Register(ctx context.Context, schema *v2.BatonActionSchema, handler ActionHandler) error

Register registers a global action using the name from the schema.

func (*ActionManager) RegisterAction deprecated

func (a *ActionManager) RegisterAction(ctx context.Context, name string, schema *v2.BatonActionSchema, handler ActionHandler) error

Deprecated: Use Register instead. RegisterAction registers a global action (not scoped to a resource type).

func (*ActionManager) RegisterResourceAction added in v0.6.9

func (a *ActionManager) RegisterResourceAction(
	ctx context.Context,
	resourceTypeID string,
	schema *v2.BatonActionSchema,
	handler ActionHandler,
) error

RegisterResourceAction registers a resource-scoped action.

func (*ActionManager) UnregisterAction

func (a *ActionManager) UnregisterAction(ctx context.Context, name string) error

type ActionRegistry added in v0.6.9

type ActionRegistry interface {
	// Register registers an action using the name from the schema.
	Register(ctx context.Context, schema *v2.BatonActionSchema, handler ActionHandler) error

	// Deprecated: Use Register instead.
	// RegisterAction registers an action.
	RegisterAction(ctx context.Context, name string, schema *v2.BatonActionSchema, handler ActionHandler) error
}

ActionRegistry provides methods for registering actions. Used by both GlobalActionProvider (global actions) and ResourceActionProvider (resource-scoped actions).

type OutstandingAction

type OutstandingAction struct {
	Id        string
	Name      string
	Status    v2.BatonActionStatus
	Rv        *structpb.Struct
	Annos     annotations.Annotations
	Err       error
	StartedAt time.Time
	sync.Mutex
	// contains filtered or unexported fields
}

func NewOutstandingAction

func NewOutstandingAction(id, name string) *OutstandingAction

func (*OutstandingAction) Result added in v0.23.0

Result returns the action's identity and current outcome. The snapshot is internally consistent; the returned message and annotations are owned by the action and must not be modified.

func (*OutstandingAction) SetError added in v0.2.72

func (oa *OutstandingAction) SetError(ctx context.Context, err error)

SetError records the error and marks the action failed in one critical section, so no snapshot can observe the error with a non-terminal status. A FAILED action may refresh its error payload, but a COMPLETE action stays complete. This is a real handler failure, so it clears any provisional cancellation mark.

func (*OutstandingAction) SetStatus

func (oa *OutstandingAction) SetStatus(ctx context.Context, status v2.BatonActionStatus)

type ResourceTypeActionRegistry deprecated added in v0.6.9

type ResourceTypeActionRegistry = ActionRegistry

Deprecated: Use ActionRegistry instead. ResourceTypeActionRegistry is an alias for ActionRegistry for backwards compatibility.

type ReturnField added in v0.6.9

type ReturnField struct {
	Key   string
	Value *structpb.Value
}

ReturnField represents a key-value pair for action return values.

func NewBoolReturnField added in v0.6.9

func NewBoolReturnField(key string, value bool) ReturnField

NewBoolReturnField creates a return field with a bool value.

func NewEntitlementListReturnField added in v0.7.9

func NewEntitlementListReturnField(key string, entitlements []*v2.Entitlement) (ReturnField, error)

NewEntitlementListReturnField creates a return field with a list of Entitlement proto values.

func NewGrantListReturnField added in v0.7.9

func NewGrantListReturnField(key string, grants []*v2.Grant) (ReturnField, error)

NewGrantListReturnField creates a return field with a list of Grant proto values.

func NewListReturnField added in v0.6.9

func NewListReturnField(key string, values []*structpb.Value) ReturnField

NewListReturnField creates a return field with a list of arbitrary values.

func NewNumberListReturnField added in v0.6.9

func NewNumberListReturnField(key string, values []float64) ReturnField

NewNumberListReturnField creates a return field with a list of number values.

func NewNumberReturnField added in v0.6.9

func NewNumberReturnField(key string, value float64) ReturnField

NewNumberReturnField creates a return field with a number value.

func NewResourceIdListReturnField added in v0.6.9

func NewResourceIdListReturnField(key string, resourceIDs []*v2.ResourceId) (ReturnField, error)

NewResourceIdListReturnField creates a return field with a list of ResourceId proto values.

func NewResourceIdReturnField added in v0.6.9

func NewResourceIdReturnField(key string, resourceId *v2.ResourceId) (ReturnField, error)

NewResourceIdReturnField creates a return field with a ResourceId proto value.

func NewResourceListReturnField added in v0.6.9

func NewResourceListReturnField(key string, resources []*v2.Resource) (ReturnField, error)

NewResourceListReturnField creates a return field with a list of Resource proto values.

func NewResourceReturnField added in v0.6.9

func NewResourceReturnField(key string, resource *v2.Resource) (ReturnField, error)

NewResourceReturnField creates a return field with a Resource proto value.

func NewReturnField added in v0.6.9

func NewReturnField(key string, value *structpb.Value) ReturnField

NewReturnField creates a new return field with the given key and value.

func NewStringListReturnField added in v0.6.9

func NewStringListReturnField(key string, values []string) ReturnField

NewStringListReturnField creates a return field with a list of string values.

func NewStringReturnField added in v0.6.9

func NewStringReturnField(key string, value string) ReturnField

NewStringReturnField creates a return field with a string value.

Jump to

Keyboard shortcuts

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