agent

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Name        string                        `json:"action"`
	Input       map[string]*common.InputItem  `json:"input"`
	Output      map[string]*common.OutputItem `json:"output"`
	Display     string                        `json:"display"`
	Description string                        `json:"description"`
	Aggregation []ActionAggregateItem         `json:"aggregate,omitempty"`

	sync.Mutex
	// contains filtered or unexported fields
}

Action describes an individual action in an agent

func (*Action) AggregateResult

func (a *Action) AggregateResult(result map[string]interface{}) error

AggregateResult receives a result and aggregate all the data found in it, most errors are squashed since aggregation are called during processing of replies and we do not want to fail a reply just because aggregation failed, thus this is basically a best efforts kind of thing on purpose

func (*Action) AggregateResultJSON

func (a *Action) AggregateResultJSON(jres []byte) error

AggregateResultJSON receives a JSON reply and aggregate all the data found in it

func (*Action) AggregateSummaryFormattedStrings

func (a *Action) AggregateSummaryFormattedStrings() (map[string][]string, error)

AggregateSummaryFormattedStrings produce a formatted string for each output item that has a aggregate summary defined

func (*Action) AggregateSummaryJSON

func (a *Action) AggregateSummaryJSON() ([]byte, error)

AggregateSummaryJSON produce a JSON representation of aggregate results for every output item that has a aggregate summary defined

func (*Action) AggregateSummaryStrings

func (a *Action) AggregateSummaryStrings() (map[string]map[string]string, error)

AggregateSummaryStrings produce a map of results for every output item that has a aggregate summary defined

func (*Action) DisplayMode added in v0.16.0

func (a *Action) DisplayMode() string

DisplayMode is the configured display mode

func (*Action) GetInput added in v0.16.0

func (a *Action) GetInput(i string) (*common.InputItem, bool)

GetInput gets a named input

func (*Action) GetOutput added in v0.16.0

func (a *Action) GetOutput(o string) (*common.OutputItem, bool)

GetOutput gets a named output

func (*Action) InputNames

func (a *Action) InputNames() (names []string)

InputNames retrieves all valid input names

func (*Action) OutputNames

func (a *Action) OutputNames() (names []string)

OutputNames retrieves all valid output names

func (*Action) RenderConsole added in v0.22.0

func (a *Action) RenderConsole() ([]byte, error)

func (*Action) RenderMarkdown added in v0.22.0

func (a *Action) RenderMarkdown() ([]byte, error)

func (*Action) RequiresInput

func (a *Action) RequiresInput(input string) bool

RequiresInput reports if an input is required

func (*Action) SetDefaults added in v0.23.0

func (a *Action) SetDefaults(inputs map[string]interface{}) error

SetDefaults looks through inputs and sets default values on any values with defaults that's not been set

func (*Action) SetOutputDefaults

func (a *Action) SetOutputDefaults(results map[string]interface{})

SetOutputDefaults adds items to results that have defaults declared in the DDL but not found in the result

func (*Action) ValidateAndConvertToDDLTypes

func (a *Action) ValidateAndConvertToDDLTypes(args map[string]string) (result map[string]interface{}, warnings []string, err error)

ValidateAndConvertToDDLTypes takes a map of strings like you might receive from the CLI, convert each item to the correct type according to the DDL type hints associated with inputs, validates its valid according to the DDL hints and returns a map of interface{} ready for conversion to JSON that would then have the correct types

func (*Action) ValidateInputString

func (a *Action) ValidateInputString(input string, val string) (warnings []string, err error)

ValidateInputString attempts to convert a string to the correct type and validate it based on the DDL spec

func (*Action) ValidateInputValue

func (a *Action) ValidateInputValue(input string, val interface{}) (warnings []string, err error)

ValidateInputValue validates the input matches requirements in the DDL

func (*Action) ValidateRequestData

func (a *Action) ValidateRequestData(data map[string]interface{}) (warnings []string, err error)

ValidateRequestData validates request data against the DDL

func (*Action) ValidateRequestJSON

func (a *Action) ValidateRequestJSON(req json.RawMessage) (warnings []string, err error)

ValidateRequestJSON receives request data in JSON format and validates it against the DDL

type ActionAggregateItem

type ActionAggregateItem struct {
	Function  string          `json:"function"`
	Arguments json.RawMessage `json:"args"`
}

ActionAggregateItem describes a aggregate function to summarize data

func (*ActionAggregateItem) OutputName

func (a *ActionAggregateItem) OutputName() string

OutputName is the name of the output being aggregated

type DDL

type DDL struct {
	Schema         string           `json:"$schema"`
	Metadata       *agents.Metadata `json:"metadata"`
	Actions        []*Action        `json:"actions"`
	SourceLocation string           `json:"-"`
}

DDL represents the schema of a mcorpc agent and is at a basic level compatible with the mcollective agent ddl format

func CachedDDL added in v0.19.0

func CachedDDL(a string) (*DDL, error)

CachedDDL is a parsed and loaded DDL for the agent a TODO: remove

func FindLocally added in v0.25.0

func FindLocally(agent string, libdirs []string) (*DDL, error)

FindLocally looks in the supplied libdirs for a DDL file for a specific agent TODO: remove

func New

func New(file string) (*DDL, error)

New creates a new DDL from a JSON file

func NewFromBytes added in v0.25.0

func NewFromBytes(dat []byte) (*DDL, error)

func (*DDL) ActionInterface

func (d *DDL) ActionInterface(action string) (*Action, error)

ActionInterface looks up an Action by name

func (*DDL) ActionNames

func (d *DDL) ActionNames() []string

ActionNames is a list of known actions defined by a DDL

func (*DDL) HaveAction

func (d *DDL) HaveAction(action string) bool

HaveAction determines if an action is known

func (*DDL) RenderConsole added in v0.22.0

func (d *DDL) RenderConsole() ([]byte, error)

RenderConsole create console appropriate output for agent provider ddls

func (*DDL) RenderMarkdown added in v0.22.0

func (d *DDL) RenderMarkdown() ([]byte, error)

RenderMarkdown create markdown appropriate output for agent provider ddls

func (*DDL) Timeout

func (d *DDL) Timeout() time.Duration

Timeout is the timeout for this agent

func (*DDL) ToRuby

func (d *DDL) ToRuby() (string, error)

ToRuby generates a ruby DDL from a go DDL

func (*DDL) ValidateAndConvertToDDLTypes

func (d *DDL) ValidateAndConvertToDDLTypes(action string, args map[string]string) (result map[string]interface{}, warnings []string, err error)

ValidateAndConvertToDDLTypes converts args to the correct data types as declared in the DDL and validates everything

Jump to

Keyboard shortcuts

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