client

package
v0.12.0-gdd3da8f Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRetries             = 5
	IntervalBetweenRetries = 200 * time.Millisecond
)
View Source
const (
	Version = "v1alpha"

	KindConfiguration      = "Configuration"
	KindFiniteStateMachine = "FiniteStateMachine"
	KindEvent              = "EventRequest"

	CmdGet     = "get"
	CmdSend    = "send"
	CmdVersion = "version"

	StdinFlag = "--"
)

Variables

View Source
var (
	// ConfigDefaultDir points to the directory in the user's HOME folder where configuration and Certificates are kept
	ConfigDefaultDir = path.Join(os.Getenv("HOME"), ".fsm")

	// CertsDir is the folder holding the X.509 Certificates and, optionally, the root CA Cert
	CertsDir = path.Join(ConfigDefaultDir, "certs")

	// CaCert is the name of the root CA X.509 Certificate for TLS Auth
	CaCert = "ca.pem"
)
View Source
var SendHandlers = HandlersMap{
	KindConfiguration: func(clt *CliClient, data []byte) (resp interface{}, grpcErr error) {
		var c ConfigEntity
		err := yaml.Unmarshal(data, &c)
		if err != nil {
			return nil, err
		}
		return clt.PutConfiguration(context.Background(), c.Spec)
	},
	KindFiniteStateMachine: func(clt *CliClient, data []byte) (resp interface{}, grpcErr error) {
		var fsm FsmEntity
		err := yaml.Unmarshal(data, &fsm)
		if err != nil {
			return nil, err
		}
		request := &protos.PutFsmRequest{Id: fsm.Id, Fsm: fsm.Spec}
		return clt.PutFiniteStateMachine(context.Background(), request)
	},
	KindEvent: func(clt *CliClient, data []byte) (resp interface{}, grpcErr error) {
		var evt EventRequestEntity
		err := yaml.Unmarshal(data, &evt)
		if err != nil {
			return nil, err
		}
		return clt.sendEvent(evt.Spec)
	},
}

Functions

This section is empty.

Types

type CliClient

type CliClient struct {
	protos.StatemachineServiceClient
}

func NewClient

func NewClient(address string, hasTls bool) *CliClient

func (*CliClient) Get

func (c *CliClient) Get(kind, id string) error

Get will retrieve the required entity from the server and generate the YAML representation accordingly. It takes two arguments, the kind and the id of the entity, and prints the contents returned by the server to stdout (or returns an error if not found)

func (*CliClient) Send

func (c *CliClient) Send(path string) error

Send processes CLI commands of the form `send config.yaml` by parsing the YAML according to its contents, dynamically adjusting the types. It only takes one argument, the path to the YAML file or `--` to use stdin

type ConfigEntity

type ConfigEntity struct {
	GenericEntity `yaml:",inline"`
	Spec          *protos.Configuration `yaml:"spec"`
}

type EventRequestEntity

type EventRequestEntity struct {
	GenericEntity `yaml:",inline"`
	Spec          *protos.EventRequest `yaml:"spec"`
}

type FsmEntity

type FsmEntity struct {
	GenericEntity `yaml:",inline"`
	Spec          *protos.FiniteStateMachine `yaml:"spec"`
}

type GenericEntity

type GenericEntity struct {
	Version string `yaml:"apiVersion"`
	Kind    string `yaml:"kind"`
	Id      string `yaml:"id"`
}

A GenericEntity is the "wrapper" type that is sent to the CLI and wraps the entity (defined in the Spec) which will be sent to the FSM Server. It has an optional Id for those requests that need it (typically, when storing a new FSM or sending an Event); if unset, a new random UUID will be generated by the server.

type HandlersMap

type HandlersMap = map[string]func(*CliClient, []byte) (resp interface{}, grpcErr error)

Jump to

Keyboard shortcuts

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