sbsdk

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: MPL-2.0 Imports: 8 Imported by: 4

Documentation

Index

Constants

View Source
const (
	NUMBER_TYPE  = "number"
	BOOLEAN_TYPE = "bool"
	STRING_TYPE  = "string"
	OBJECT_TYPE  = "object"
	MAP_TYPE     = "map"
	LIST_TYPE    = "list"
	INVALID_TYPE = "invalid"
)

Variables

This section is empty.

Functions

func InvokeActionEvaluation

func InvokeActionEvaluation(action Action, p Provider, name string, config []byte, input []byte) ([]byte, error)

func MarshalVal

func MarshalVal(schema Schema, val cty.Value) ([]byte, error)

func UnmarshalVal

func UnmarshalVal(schema Schema, data []byte) (cty.Value, error)

Types

type Action

type Action interface {
	Function
	// Evaluate accepts two value parameters. The first contains provider Config details. The second
	//is a value that should map to the Function.ConfigurationSchema output. This
	// is the main function called by the runner service when a particular action is being processed. In
	// a standard integration provider, this is where the guts of integration code will be.
	Evaluate(config cty.Value, input cty.Value) (cty.Value, error)
}

type AttrSchema

type AttrSchema struct {
	Name     string
	Required bool
	Type     Type
}

AttrSchema represents a key/val coming from the provided data structure

func OptionalAttrSchema

func OptionalAttrSchema(name string, valType Type) *AttrSchema

func RequiredAttrSchema

func RequiredAttrSchema(name string, valType Type) *AttrSchema

func (*AttrSchema) Decode

func (b *AttrSchema) Decode() hcldec.Spec

type BlockSchema

type BlockSchema struct {
	Name     string
	Required bool
	Nested   Schema
}

BlockSchema maps to block types from the Config. Blocks with labels are not supported, meaning only one block type per provided Config is permitted

func OptionalBlockSchema

func OptionalBlockSchema(name string, nested Schema) *BlockSchema

func (*BlockSchema) Decode

func (b *BlockSchema) Decode() hcldec.Spec

type EvaluateServerPayload

type EvaluateServerPayload struct {
	Name   string
	Config []byte
	Input  []byte
}

type Function

type Function interface {
	// ConfigurationSchema returns an ObjectSpec that returns all required/optional blocks and attributes
	// in an Action or Trigger. This should include all general configuration settings, as well as all details
	// pertinent to an individual interaction (api call, event publish, etc.) with the integration
	ConfigurationSchema() (ObjectSchema, error)
	// OutputType provides a schema structure for the result of an Action or Trigger. This is an essential component
	// of using output from one action in a workflow as the Input of another, as well as pre-deployment
	// configuration validation. Note, this does not return an ObjectSchema because that type is primarily
	// used for helping the calling application know how the hcl Config data should look.
	OutputType() (Type, error)
}

type ObjectSchema

type ObjectSchema map[string]Schema

ObjectSchema is primarily used as root of all schemas in switchboard. This enforces a key/value style of Config for anything using this. Many Provider interface methods will return this to enforce a certain style of how providers expect user Config data to look.

func (*ObjectSchema) Decode

func (s *ObjectSchema) Decode() hcldec.Spec

type Provider

type Provider interface {
	//Init is called shortly after loading a plugin, and provides some stateful values
	//to the provider, such as auth keys.
	//
	//The byte array param must be the result of json.Marshal
	//from the github.com/zclconf/go-cty/cty/json package and should immediately be
	//unmarshalled into a cty.Value based on the type as inferred from the hcldec.ObjectSpec from InitSchema
	Init([]byte) error

	//InitSchema is used by the CLI to validate user provided Config, and is also used in Init
	//to unmarshal the string into a cty.Value
	InitSchema() (ObjectSchema, error)
	ActionNames() ([]string, error)
	ActionEvaluate(name string, config []byte, input []byte) ([]byte, error)
	ActionConfigurationSchema(name string) (ObjectSchema, error)
	ActionOutputType(name string) (Type, error)
}

Provider is the main interface that must be implemented by every integration provider in order to work with the Switchboard runner service. In addition to provider specific methods, the provider also includes proxy methods to call on specific Action or Trigger implementations (this way, we don't have to register every Action and Trigger as a plugin)

Every method returns an error as the last return type so that we can gracefully deal with any RPC related errors in the go-plugin client implementation of this interface.

func NewProviderRPCClient

func NewProviderRPCClient() Provider

type ProviderPlugin

type ProviderPlugin struct {
	Impl Provider
}

func (*ProviderPlugin) Client

func (p *ProviderPlugin) Client(_ *plugin.MuxBroker, c *rpc.Client) (interface{}, error)

func (*ProviderPlugin) Server

func (p *ProviderPlugin) Server(*plugin.MuxBroker) (interface{}, error)

type ProviderRPCClient

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

func (*ProviderRPCClient) ActionConfigurationSchema

func (p *ProviderRPCClient) ActionConfigurationSchema(name string) (ObjectSchema, error)

func (*ProviderRPCClient) ActionEvaluate

func (p *ProviderRPCClient) ActionEvaluate(name string, config []byte, input []byte) ([]byte, error)

func (*ProviderRPCClient) ActionNames

func (p *ProviderRPCClient) ActionNames() ([]string, error)

func (*ProviderRPCClient) ActionOutputType

func (p *ProviderRPCClient) ActionOutputType(name string) (Type, error)

func (*ProviderRPCClient) Init

func (p *ProviderRPCClient) Init(val []byte) error

func (*ProviderRPCClient) InitSchema

func (p *ProviderRPCClient) InitSchema() (ObjectSchema, error)

type ProviderRPCServer

type ProviderRPCServer struct {
	Impl Provider
}

func (*ProviderRPCServer) ActionConfigurationSchema

func (p *ProviderRPCServer) ActionConfigurationSchema(name string, reply *ObjectSchema) error

func (*ProviderRPCServer) ActionEvaluate

func (p *ProviderRPCServer) ActionEvaluate(payload EvaluateServerPayload, reply *[]byte) error

func (*ProviderRPCServer) ActionNames

func (p *ProviderRPCServer) ActionNames(_ any, reply *[]string) error

func (*ProviderRPCServer) ActionOutputType

func (p *ProviderRPCServer) ActionOutputType(name string, reply *Type) error

func (*ProviderRPCServer) Init

func (p *ProviderRPCServer) Init(val []byte, _ *any) error

func (*ProviderRPCServer) InitSchema

func (p *ProviderRPCServer) InitSchema(_ any, reply *ObjectSchema) error

type Schema

type Schema interface {
	//Decode transforms a Schema struct into a hcldec.Spec so that hcl Config data can be serialized
	//into a usable value and passed to the provider. This is primarily used in the runner application
	//where hcl is being parsed.
	Decode() hcldec.Spec
}

Schema is an interface implemented by various serializable structs that are used by provider implementations to define the structure of hcl Config data as it is passed by the user. Schemas are pulled from the runner of CLI to tell the hcl decoder what the user Config should look like. All structs that implement this interface MUST use exportable/public properties. non-exportable/private properties will not work when sending data over the wire.

type Trigger

type Trigger interface {
	Function
	IsRegistered(config cty.Value, input cty.Value) (bool, error)
	// Register accepts two value parameters. The first contains provider Config details. The second is the
	// Input data for the integration. Register is responsible for working with the respective integration to
	//register the trigger with switchboard. This may be an event-subscription, polling api, or webhook registration.
	Register(config cty.Value, input cty.Value) (string, error)
	Unregister(config cty.Value, input cty.Value) (string, error)
	// ShouldListen tells the caller if it should listen for messages directly from the plugin.
	// Only applicable for unique cases like event queues where messages are received at the subscription point
	ShouldListen() (bool, error)
	// Listen is passed a callback that will be fired any time a trigger where ShouldListen() = true receives
	// an event from the subscription point
	Listen(cb func(output cty.Value)) error
}

type Type

type Type struct {
	//Name is a string representation of the underlying type
	Name string `json:"Name"`
	//NestedValues is used exclusively for an "object" type
	NestedValues *map[string]Type `json:"nestedValues,omitempty"`

	//InternalType is used to represent what type the value of a list or map value is.
	InternalType *Type `json:"internalType,omitempty"`
}

Type is a serializable data structure that helps the CLI and runner understand what data structures in configuration should look like.

var Bool Type

Bool represents a primitive boolean type

var Invalid Type

Invalid is used as an error value for types

var Number Type

Number represents a primitive numeric type

var String Type

String represents a primitive string type

func List

func List(valType Type) Type

func Map

func Map(valType Type) Type

Map creates an unstructured map of passed key/values as a Type object. Use this when the map keys are unknown or variable

func Object

func Object(data map[string]Type) Type

Object creates structured map of passes key/values as a Type object. Use this when your map keys are known and static

func (*Type) ToCty

func (t *Type) ToCty() cty.Type

ToCty is used for converting types into the cty.Type. The cty library is a hard dep in hcl library for decoding user config values, but it is not serializable, which is why we have our own type representation here.

Jump to

Keyboard shortcuts

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