actions

package
v0.6.13 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 16 Imported by: 9

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 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 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) 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
}

func NewOutstandingAction

func NewOutstandingAction(id, name string) *OutstandingAction

func (*OutstandingAction) SetError added in v0.2.72

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

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 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