helpers

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DebugCount int

Debug Level

Functions

func ColorResults added in v0.0.3

func ColorResults(responses []*tx.Response, regexes []*colorize.Colorize)

Color the templates

func ValidateNodeFilter

func ValidateNodeFilter(NodeFilter *[]string, nodes map[string]nodes.Node) error

Ensure the NodeFilter contains valid nodes If empty, ensure it contains ALL the nodes

func WatchFS added in v0.0.9

func WatchFS(ctx *Context, cb func(string)) *fsnotify.Watcher

func WsErrorf added in v0.0.3

func WsErrorf(ws chan<- interface{}, msg string, args ...interface{})

func WsMakeChannel added in v0.0.21

func WsMakeChannel(conn *websocket.Conn) chan<- interface{}

func WsWarnf added in v0.0.3

func WsWarnf(ws chan<- interface{}, msg string, args ...interface{})

Types

type Context

type Context struct {
	// the Kong Command()
	Command    string
	DebugCount int
	Settings   *Settings
	Async      bool

	// Topology filename, used by config, serve
	TopoFilename   string
	LabctlFilename string
	// used by config, serve
	TemplatePaths *orderedmap.OrderedMap[string, string]
	// used by config
	TemplateList []string
	// Used by config
	NodeFilter []string

	Topo Topo

	Template *template.Template

	// Output of any config command. Either to the terminal or websocket
	Output ResultOutput
}

func (*Context) AsJson added in v0.0.21

func (ctx *Context) AsJson() *ContextJson

func (*Context) InitPaths added in v0.0.21

func (c *Context) InitPaths(topofile string, paths []string) (string, error)

Initialize the TopFile and TemplatePaths

func (*Context) Load

func (c *Context) Load() error

func (*Context) TemplatePathsSlice added in v0.0.3

func (c *Context) TemplatePathsSlice() []string

Convert the TemplatePath stored in an orderedmap to a []string

type ContextJson added in v0.0.21

type ContextJson struct {
	Command       string   `json:"command"`
	TopoFile      string   `json:"topofile"`
	TopoError     string   `json:"topoerror"`
	TemplatePaths []string `json:"template_paths"`
}

type LinkJson

type LinkJson struct {
	clab.Link
	Vars map[string]interface{} `json:"vars,omitempty"`
}

type LogOutput added in v0.0.3

type LogOutput struct{}

The standard output to the log. Implements ResultOutput

func (*LogOutput) Error added in v0.0.3

func (l *LogOutput) Error(node string, msg string)

func (*LogOutput) Info added in v0.0.3

func (l *LogOutput) Info(node string, msg string)

func (*LogOutput) LogResponses added in v0.0.3

func (l *LogOutput) LogResponses(obj []*tx.Response, _ *config.NodeConfig)

func (*LogOutput) PreferStdout added in v0.0.3

func (l *LogOutput) PreferStdout() bool

type NodeJson

type NodeJson struct {
	types.ContainerDetails
	Vars map[string]interface{} `json:"vars,omitempty"`
}

type OutputAsJson added in v0.0.3

type OutputAsJson interface{}

type OutputAsLog added in v0.0.3

type OutputAsLog interface{}

type ResultOutput added in v0.0.3

type ResultOutput interface {
	LogResponses([]*tx.Response, *config.NodeConfig)
	Info(string, string)
	Error(string, string)
	PreferStdout() bool
}

type Settings

type Settings struct {
	Colors []*colorize.Colorize `yaml:"colorize"`

	Kindmap map[string]tx.KindDef `yaml:"kindmap"`
}

func NewSettings

func NewSettings(defaults ...bool) *Settings

func (*Settings) AddSettings

func (s *Settings) AddSettings(path string, silent bool) error

func (*Settings) InitColors

func (s *Settings) InitColors() error

type Template

type Template struct {
	Name    string   `json:"name"`
	P       string   `json:"p"`
	ShadowP []string `json:"shadow"`
	Value   string   `json:"value"`
}

func (*Template) Load

func (t *Template) Load(ctx *Context) error

type Templates

type Templates map[string]*Template

func LoadTemplates

func LoadTemplates(ctx *Context) (Templates, error)

Load the template from the ctx.TemplatePaths

type Topo

type Topo struct {
	Name string
	// Issue with the topofile
	TopoError string
	Clab      *clab.CLab
}

func (*Topo) AsJson

func (topo *Topo) AsJson() (TopoJson, error)

func (*Topo) Load

func (topo *Topo) Load(topoFile string) error

func (*Topo) Print

func (topo *Topo) Print() error

func (*Topo) VarsAsJson

func (topo *Topo) VarsAsJson() (Vars, error)

type TopoJson

type TopoJson struct {
	Name   string              `json:"name"`
	Prefix string              `json:"prefix"`
	Nodes  map[string]NodeJson `json:"nodes,omitempty"`
	Links  map[int]LinkJson    `json:"links,omitempty"`
}

type Vars

type Vars map[string]map[string]interface{}

type WebSocketOutput added in v0.0.3

type WebSocketOutput struct {
	Ws chan<- interface{}
}

Implements ResultOutput

func (*WebSocketOutput) Error added in v0.0.3

func (ws *WebSocketOutput) Error(node string, msg string)

func (*WebSocketOutput) Info added in v0.0.3

func (ws *WebSocketOutput) Info(node string, msg string)

func (*WebSocketOutput) LogResponses added in v0.0.3

func (ws *WebSocketOutput) LogResponses(obj []*tx.Response, nc *config.NodeConfig)

func (*WebSocketOutput) PreferStdout added in v0.0.3

func (l *WebSocketOutput) PreferStdout() bool

type WsConfig added in v0.0.3

type WsConfig struct {
	Cmd     string             `json:"cmd,omitempty"`
	Results []*tx.Response     `json:"results,omitempty"`
	Input   *config.NodeConfig `json:"env"`
}

type WsMessage added in v0.0.3

type WsMessage struct {
	Code     WsMsgCode   `json:"code"`
	Msg      string      `json:"msg,omitempty"`
	UiData   *WsUiData   `json:"uidata,omitempty"`
	Template *WsTemplate `json:"template,omitempty"`
	Config   *WsConfig   `json:"config,omitempty"`
}

func WsFsChange added in v0.0.16

func WsFsChange(msg string) *WsMessage

a FSChange message

func WsUiUpdate added in v0.0.21

func WsUiUpdate(ctx *Context) *WsMessage

func (*WsMessage) String added in v0.0.3

func (w *WsMessage) String() string

WsMessage stringer

func (*WsMessage) UnmarshalJson added in v0.0.3

func (w *WsMessage) UnmarshalJson(data []byte) error

type WsMsgCode added in v0.0.3

type WsMsgCode string
const (
	WscError    WsMsgCode = "error"    // .Msg
	WscWarn     WsMsgCode = "warn"     // .Msg
	WscTemplate WsMsgCode = "template" // .Template
	WscUiData   WsMsgCode = "uidata"   // .UiData
	WscConfig   WsMsgCode = "config"   // .Config
	WscFsChange WsMsgCode = "fschange" // .Msg contains the filename
)

type WsTemplate added in v0.0.3

type WsTemplate struct {
	Id         string                 `json:"id,omitempty"`
	Name       string                 `json:"name,omitempty"`
	Template   string                 `json:"template,omitempty"`
	Vars       map[string]interface{} `json:"vars,omitempty"`
	Result     string                 `json:"result,omitempty"`
	ResultYaml map[string]interface{} `json:"resulty,omitempty"`
}

Used by the frontend to request a template to be rendered

func (*WsTemplate) ClearInput added in v0.0.3

func (t *WsTemplate) ClearInput()

Clear the template command's input (typically before replying)

func (*WsTemplate) Render added in v0.0.3

func (t *WsTemplate) Render(ctx *Context) error

Render the template

type WsUiData added in v0.0.3

type WsUiData struct {
	Options   map[string]interface{} `json:"options"`   // A generic options dictionary for persistent UI options
	Layouts   layouts                `json:"layouts"`   // layouts is a property of v-network-graph
	Templates map[string]string      `json:"templates"` // Templates used by the UI etc
	Context   *ContextJson           `json:"context"`   // Context with filename, template paths etc
}

func NewWsUiData added in v0.0.3

func NewWsUiData() *WsUiData

func (*WsUiData) Print added in v0.0.3

func (u *WsUiData) Print()

func (*WsUiData) ReadFile added in v0.0.3

func (u *WsUiData) ReadFile(ctx *Context) error

func (*WsUiData) WriteFile added in v0.0.3

func (u *WsUiData) WriteFile(ctx *Context)

Directories

Path Synopsis
The discovery package allows test processing of router CLI output It leverages TextFSMto parse the output and apply a golang template to the output
The discovery package allows test processing of router CLI output It leverages TextFSMto parse the output and apply a golang template to the output

Jump to

Keyboard shortcuts

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