sbsdk

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: MPL-2.0 Imports: 7 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"
	DYNAMIC_TYPE           = "dynamic"
	INVALID_TYPE           = "invalid"
	TYPE_NAME_KEY          = "type_name"
	TYPE_NESTED_VALUES_KEY = "nested_values"
	TYPE_INTERNAL_TYPE_KEY = "internal_type"
)

Variables

View Source
var HandshakeConfig = plugin.HandshakeConfig{
	ProtocolVersion:  2,
	MagicCookieKey:   "Switchboard",
	MagicCookieValue: "Plugin",
}

Functions

func MapCtyValueToByteString added in v0.0.7

func MapCtyValueToByteString(val cty.Value, outputType Type) ([]byte, error)

func MapInputToCtyValue added in v0.0.7

func MapInputToCtyValue(input []byte, schema ObjectSchema) (cty.Value, 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 {
	// 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)
	//Evaluate 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(contextId string, input cty.Value) (cty.Value, error)
}

Action to be implemented by providers for each individual method/endpoint tied the provider. Each action should be inclusive of all possible ways of calling a method/endpoint for the integration.

type ActionEvalData added in v0.0.5

type ActionEvalData struct {
	ContextId string
	Name      string
	Input     []byte
}

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 GlobalConfig added in v0.0.5

type GlobalConfig struct {
	//PublicUri tells each provider where they should register
	//triggers that are http based
	PublicIngestUri string
	//PrivateUri is used by providers that have event subscriptions that are received directly by the provider,
	//such as event-queue triggers or polling-style event listeners. This
	PrivateIngestUri string
}

GlobalConfig contains details related to the core switchboard instance that each provider may use as they see fit in their implementations

type InitData added in v0.0.5

type InitData struct {
	GlobalConfig GlobalConfig
	UserConfig   []byte
}

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 gives the provider access to certain
	//data owned by the runner
	//
	//It hands the provider an instance of the ContextProvider interface, which will
	//be implemented by the runner, and various methods should be called to get context/config
	//information from the runner.
	Init(runnerProvider RunnerProvider) (ProviderConfig, 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 returns a list of available actions from a provider
	ActionNames() ([]string, error)

	//ActionEvaluate is the implementation of a particular action as defined by the provider.
	//It is called by its name as listed in ActionNames. The input param must conform to the schema provided by ActionConfigurationSchema
	ActionEvaluate(contextId string, name string, input []byte) ([]byte, error)
	//ActionConfigurationSchema returns a data structure representing the expected schema
	//in the user-provided hcl configuration file for a particular action
	ActionConfigurationSchema(name string) (ObjectSchema, error)
	//ActionOutputType returns a data structure representing the result-type of a particular
	//action on success. This is used for both converting data to a dynamic cty.Value, and
	//for validating correct user-defined configuration
	ActionOutputType(name string) (Type, error)

	//TriggerKeyNames returns a list of keys that an action can filter by. This method is
	//used during the validation process to make sure action filters are valid
	TriggerKeyNames() ([]string, error)
	//TriggerConfigurationSchema is similar to ActionConfigurationSchema, but for triggers
	TriggerConfigurationSchema() (ObjectSchema, error)
	//MapPayloadToTriggerKey maps an incoming event to a trigger key. This is helpful
	//for actions that want to fire on isolated event types and for fetching type hints.
	//This is particularly useful for triggers that have 2+ event types that the subscription listens to
	MapPayloadToTriggerKey([]byte) (string, error)
	//TriggerOutputType provides the runner with a type hint based on the value that gets returned
	//from MapPayloadToTriggerKey.
	TriggerOutputType(string) (Type, error)

	//CreateSubscription subscribes to the provider for one trigger.
	//It returns a representation of the resulting state of the subscription in raw JSON byte string
	CreateSubscription(contextId string, input []byte) ([]byte, error)
	//ReadSubscription will get the current state value of the trigger from the integration provider
	// in raw JSON byte string
	ReadSubscription(contextId string, subscriptionId string) ([]byte, error)
	//UpdateSubscription will update the trigger and return the new state value to the runner
	// as a raw JSON byte string
	UpdateSubscription(contextId string, subscriptionId string, input []byte) ([]byte, error)
	//DeleteSubscription with remove the trigger and event subscription to the vendor
	DeleteSubscription(contextId string, subscriptionId string) error
}

Provider is the main network interface that must be implemented by every integration provider in order to work with the Switchboard runner service.

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 ProviderConfig added in v0.0.5

type ProviderConfig struct {
	SubscriptionsRegisteredTogether bool
}

ProviderConfig is some static information the runner can use to decipher how to process certain types of provider setups.

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(contextId string, name string, 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) CreateSubscription added in v0.0.5

func (p *ProviderRPCClient) CreateSubscription(contextId string, input []byte) ([]byte, error)

func (*ProviderRPCClient) DeleteSubscription added in v0.0.5

func (p *ProviderRPCClient) DeleteSubscription(contextId string, subscriptionId string) error

func (*ProviderRPCClient) Init

func (p *ProviderRPCClient) Init(runnerProvider RunnerProvider) (ProviderConfig, error)

func (*ProviderRPCClient) InitSchema

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

func (*ProviderRPCClient) MapPayloadToTriggerKey added in v0.0.6

func (p *ProviderRPCClient) MapPayloadToTriggerKey(data []byte) (string, error)

func (*ProviderRPCClient) ReadSubscription added in v0.0.5

func (p *ProviderRPCClient) ReadSubscription(contextId string, subscriptionId string) ([]byte, error)

func (*ProviderRPCClient) TriggerConfigurationSchema added in v0.0.5

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

func (*ProviderRPCClient) TriggerKeyNames added in v0.0.6

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

func (*ProviderRPCClient) TriggerOutputType added in v0.0.5

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

func (*ProviderRPCClient) UpdateSubscription added in v0.0.5

func (p *ProviderRPCClient) UpdateSubscription(contextId string, subscriptionId string, input []byte) ([]byte, 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 ActionEvalData, 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) CreateSubscription added in v0.0.5

func (p *ProviderRPCServer) CreateSubscription(data SubscriptionData, reply *[]byte) error

func (*ProviderRPCServer) DeleteSubscription added in v0.0.5

func (p *ProviderRPCServer) DeleteSubscription(data SubscriptionData) error

func (*ProviderRPCServer) Init

func (p *ProviderRPCServer) Init(runnerProvider RunnerProvider, reply *ProviderConfig) error

func (*ProviderRPCServer) InitSchema

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

func (*ProviderRPCServer) MapPayloadToTrigger added in v0.0.5

func (p *ProviderRPCServer) MapPayloadToTrigger(data []byte, reply *string) error

func (*ProviderRPCServer) ReadSubscription added in v0.0.5

func (p *ProviderRPCServer) ReadSubscription(data SubscriptionData, reply *[]byte) error

func (*ProviderRPCServer) TriggerConfigurationSchema added in v0.0.5

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

func (*ProviderRPCServer) TriggerOutputType added in v0.0.5

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

func (*ProviderRPCServer) UpdateSubscription added in v0.0.5

func (p *ProviderRPCServer) UpdateSubscription(data SubscriptionData, reply *[]byte) error

type RunnerProvider added in v0.0.5

type RunnerProvider interface {
	//UserConfig is a map of byte string arrays, where each byte string array should conform to the Schema
	//as specified by Provider.InitSchema method when marshaled into cty.JSON. Each key in the map is a context ID
	//which is essentially a unique configuration of the provider as defined in the user provided config
	UserConfig() map[string][]byte
	GlobalConfig() GlobalConfig
}

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 SubscriptionData added in v0.0.5

type SubscriptionData struct {
	ContextId      string
	SubscriptionId string
	InputData      []byte
}

type Type

type Type struct {
	//TypeName is a string representation of the underlying type
	TypeName string
	//NestedValues is used exclusively for an "object" type
	NestedValues *map[string]Type

	//InternalType is used to represent what type the value of a list or map value is.
	InternalType *Type
}

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 Dynamic Type

Dynamic represents a type that can be anything. This is not recommended as these values cannot be validated ahead of time in user configuration. Only use this value when the underlying type is uncertain and variable.

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 FromCtyToType added in v0.0.5

func FromCtyToType(val cty.Value, isRoot bool) (*Type, error)

func List

func List(valType Type) Type

List creates a list with known types as list values.

func Map

func Map(valType Type) Type

Map creates a map with unknown keys but known values as a Type object. Use this when the map keys are unknown/variable, but values are known

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