action

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: Apache-2.0 Imports: 11 Imported by: 13

Documentation

Index

Constants

View Source
const (
	// RequestSetNamespace is the action for when the current namespace in Octant changes.
	// The ActionRequest.Payload for this action contains a single string entry `namespace` with a value
	// of the new current namespace.
	RequestSetNamespace = "action.octant.dev/setNamespace"

	// RequestSetFilter is the action for when the filters are updated in Octant.
	// The ActionRequest.Payload for this action contains an array of key/values representing
	// the filters.
	RequestSetFilter = "action.octant.dev/setFilter"

	// RequestSetContext is the action for when the context in Octant changes.
	// The ActionRequest.Payload for this action contains a single string entry `contextName` with a value
	// of the new context.
	RequestSetContext = "action.octant.dev/setContext"

	// ActionApplyYaml is the action to apply a yaml resource configuration.
	// The ActionRequest.Payload for this action contains string entry `namespace` and a string entry
	// `update` containing the yaml configuration for a resource.
	ActionApplyYaml = "action.octant.dev/apply"
)
View Source
const (
	// DefaultAlertExpiration is the default expiration for alerts.
	DefaultAlertExpiration = 10 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	// Type is the type of alert.
	Type AlertType `json:"type"`
	// Message is the message for the alert.
	Message string `json:"message"`
	// Expiration is the time the alert expires.
	Expiration *time.Time `json:"expiration,omitempty"`
}

Alert is an alert message.

func CreateAlert

func CreateAlert(alertType AlertType, message string, expireAt time.Duration) Alert

CreateAlert creates an alert with optional expiration. If the expireAt is < 1 Expiration will be nil.

type AlertType

type AlertType string

AlertType is the type of alert.

const (
	// AlertTypeError is for error alerts.
	AlertTypeError AlertType = "ERROR"

	// AlertTypeWarning is for warning alerts.
	AlertTypeWarning AlertType = "WARNING"

	// AlertTypeInfo is for info alerts.
	AlertTypeInfo AlertType = "INFO"

	// AlertTypeSuccess is for success alerts.
	AlertTypeSuccess AlertType = "SUCCESS"
)

type Alerter

type Alerter interface {
	SendAlert(alert Alert)
}

func NewAlerter added in v0.16.0

func NewAlerter() Alerter

NewAlerter creates a new alerter

type Dispatcher

type Dispatcher interface {
	ActionName() string
	Handle(ctx context.Context, alerter Alerter, payload Payload) error
}

Dispatcher handles actions.

type DispatcherFunc

type DispatcherFunc func(ctx context.Context, alerter Alerter, payload Payload) error

DispatcherFunc is a function that will be dispatched to handle a payload.

type Dispatchers

type Dispatchers []Dispatcher

Dispatchers is a slice of Dispatcher.

func (Dispatchers) ToActionPaths

func (d Dispatchers) ToActionPaths() map[string]DispatcherFunc

ToActionPaths converts Dispatchers to a map.

type Manager

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

Manager manages actions.

func NewManager

func NewManager(logger log.Logger) *Manager

NewManager creates an instance of Manager.

func (*Manager) Dispatch

func (m *Manager) Dispatch(ctx context.Context, alerter Alerter, actionPath string, payload Payload) error

Dispatch dispatches a payload to a path.

func (*Manager) Register

func (m *Manager) Register(actionPath string, pluginName string, actionFunc DispatcherFunc) error

Register registers a dispatcher function to an action path.

func (*Manager) Unregister added in v0.14.0

func (m *Manager) Unregister(actionPath string, pluginName string)

Unregister unregisters a dispatcher function to an action path.

type NotFoundError

type NotFoundError struct {
	Path string
}

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type Payload

type Payload map[string]interface{}

Payload is an action payload.

func CreatePayload

func CreatePayload(actionName string, fields map[string]interface{}) Payload

CreatePayload creates a payload with an action name and fields.

func (Payload) Bool added in v0.10.0

func (p Payload) Bool(key string) (bool, error)

Bool returns a string from the payload.

func (Payload) Float64

func (p Payload) Float64(key string) (float64, error)

Float64 returns a float64 from the payload.

func (Payload) GroupVersionKind

func (p Payload) GroupVersionKind() (schema.GroupVersionKind, error)

GroupVersionKind extracts a GroupVersionKind from a payload.

func (Payload) Int64 added in v0.16.0

func (p Payload) Int64(key string) (int64, error)

Int64 returns a int64 from the payload.

func (Payload) OptionalString

func (p Payload) OptionalString(key string) (string, error)

OptionalString returns a string from the payload. If the string does not exist, it returns an empty string.

func (Payload) Raw added in v0.16.0

func (p Payload) Raw(key string) ([]byte, error)

Raw returns a key as bytes.

func (Payload) String

func (p Payload) String(key string) (string, error)

String returns a string from the payload.

func (Payload) StringSlice

func (p Payload) StringSlice(key string) ([]string, error)

StringSlice returns a string slice from the payload.

func (Payload) Uint16

func (p Payload) Uint16(key string) (uint16, error)

Uint16 returns a uint16 from the payload.

Directories

Path Synopsis
Package fake is a generated GoMock package.
Package fake is a generated GoMock package.

Jump to

Keyboard shortcuts

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