Documentation
¶
Overview ¶
Package compat keeps the module task types compatible with the former smart service module workers (TASK-28): string inputs are templates over the instance variables, and prescript and postscript inputs run with the script API of smart-service-module-worker-lib, ported from that library. Designs written for the workers run unchanged.
Index ¶
- Constants
- Variables
- func GetPlaceholder(variables map[string]interface{}) (result map[string]string, err error)
- func GroupIotOptionsByDevice(options []IotOption) (result map[string][]IotOption)
- func GroupIotOptionsByService(options []IotOption) (result map[string][]IotOption)
- func Namespaces() map[string]interface{}
- func RemoveScriptInputs(inputs map[string]interface{}) map[string]interface{}
- func Render(inputs map[string]any, variables map[string]any) (result map[string]any, err error)
- func Replace(str string, variables map[string]string) (string, error)
- type DeviceGroupSelection
- type DeviceSelection
- type GenericEventSource
- type ImportSelection
- type IotOption
- type ScriptEnv
- type ScriptEnvConsole
- type ScriptEnvDeviceRepo
- func (this *ScriptEnvDeviceRepo) GetAspect(id string) models.Aspect
- func (this *ScriptEnvDeviceRepo) GetAspectNode(id string) models.AspectNode
- func (this *ScriptEnvDeviceRepo) GetAspectNodes() []models.AspectNode
- func (this *ScriptEnvDeviceRepo) GetAspectNodesByIdList(ids []string) []models.AspectNode
- func (this *ScriptEnvDeviceRepo) GetAspectNodesMeasuringFunctions(id string, ancestors bool, descendants bool) []models.Function
- func (this *ScriptEnvDeviceRepo) GetAspectNodesWithMeasuringFunction(ancestors bool, descendants bool) []models.AspectNode
- func (this *ScriptEnvDeviceRepo) GetAspects() []models.Aspect
- func (this *ScriptEnvDeviceRepo) GetAspectsWithMeasuringFunction(ancestors bool, descendants bool) []models.Aspect
- func (this *ScriptEnvDeviceRepo) GetCharacteristic(id string) models.Characteristic
- func (this *ScriptEnvDeviceRepo) GetConceptWithCharacteristics(id string) models.ConceptWithCharacteristics
- func (this *ScriptEnvDeviceRepo) GetConceptWithoutCharacteristics(id string) models.Concept
- func (this *ScriptEnvDeviceRepo) GetDeviceClass(id string) models.DeviceClass
- func (this *ScriptEnvDeviceRepo) GetDeviceClasses() []models.DeviceClass
- func (this *ScriptEnvDeviceRepo) GetDeviceClassesControllingFunctions(id string) []models.Function
- func (this *ScriptEnvDeviceRepo) GetDeviceClassesFunctions(id string) []models.Function
- func (this *ScriptEnvDeviceRepo) GetDeviceClassesWithControllingFunctions() []models.DeviceClass
- func (this *ScriptEnvDeviceRepo) GetDeviceTypeSelectables(query []model.FilterCriteria, pathPrefix string, includeModified bool, ...) []model.DeviceTypeSelectable
- func (this *ScriptEnvDeviceRepo) GetFunction(id string) models.Function
- func (this *ScriptEnvDeviceRepo) GetFunctionsByType(rdfType string) []models.Function
- func (this *ScriptEnvDeviceRepo) GetLeafCharacteristics() []models.Characteristic
- func (this *ScriptEnvDeviceRepo) GetLocation(id string) models.Location
- func (this *ScriptEnvDeviceRepo) GetService(id string) models.Service
- func (this *ScriptEnvDeviceRepo) ListDeviceTypes(limit int64, offset int64, sort string, filter []model.FilterCriteria, ...) []models.DeviceType
- func (this *ScriptEnvDeviceRepo) ListHubDeviceIds(id string, asLocalId bool) []string
- func (this *ScriptEnvDeviceRepo) ReadDevice(id string) models.Device
- func (this *ScriptEnvDeviceRepo) ReadDeviceByLocalId(localId string) models.Device
- func (this *ScriptEnvDeviceRepo) ReadDeviceGroup(id string) models.DeviceGroup
- func (this *ScriptEnvDeviceRepo) ReadDeviceType(id string) models.DeviceType
- func (this *ScriptEnvDeviceRepo) ReadHub(id string) models.Hub
- type ScriptEnvInputs
- type ScriptEnvOutputs
- type ScriptEnvUtil
- func (this *ScriptEnvUtil) GetDevicesWithServiceFromEntityString(entityStr string, criteria []devicemodel.FilterCriteria) []IotOptiondeprecated
- func (this *ScriptEnvUtil) GetDevicesWithServiceFromIotOption(entity IotOption, criteria []devicemodel.FilterCriteria) []IotOption
- func (this *ScriptEnvUtil) GetUserId() string
- func (this *ScriptEnvUtil) GetUserToken() string
- func (this *ScriptEnvUtil) GroupIotOptionsByDevice(entities []IotOption) map[string][]IotOption
- func (this *ScriptEnvUtil) GroupIotOptionsByService(entities []IotOption) map[string][]IotOption
- func (this *ScriptEnvUtil) IsDeviceGroupIotOption(entity IotOption) bool
- func (this *ScriptEnvUtil) IsDeviceGroupIotOptionStr(entityStr string) booldeprecated
- func (this *ScriptEnvUtil) IsDeviceIotOption(entity IotOption) bool
- func (this *ScriptEnvUtil) IsDeviceIotOptionStr(entityStr string) booldeprecated
- func (this *ScriptEnvUtil) IsImportIotOption(entity IotOption) bool
- func (this *ScriptEnvUtil) IsImportIotOptionStr(entityStr string) booldeprecated
- type ScriptEnvVariables
- func (this *ScriptEnvVariables) DerefName(ref string) string
- func (this *ScriptEnvVariables) DerefTemplate(templ string) string
- func (this *ScriptEnvVariables) DerefValue(ref string) interface{}
- func (this *ScriptEnvVariables) Exists(name string) bool
- func (this *ScriptEnvVariables) Read(name string) interface{}deprecated
- func (this *ScriptEnvVariables) ReadValue(name string) interface{}
- func (this *ScriptEnvVariables) Ref(name string) string
- func (this *ScriptEnvVariables) Write(name string, value interface{})
- type Scripts
- type TokenSource
Constants ¶
const PostScriptPrefix = "postscript"
const PreScriptPrefix = "prescript"
Variables ¶
var ErrNoDeviceOrGroupSelection = errors.New("expect device or group selection")
var TrowErrorForUnknownDerefName = false
Functions ¶
func GetPlaceholder ¶
func GroupIotOptionsByDevice ¶
GroupIotOptionsByDevice groups a list of IotOption by their device id none device options will be grouped under the "" key
func GroupIotOptionsByService ¶
GroupIotOptionsByService groups a list of IotOption by their service id device options without serviceId will be grouped under the "" key none device options will be grouped under the "" key
func Namespaces ¶
func Namespaces() map[string]interface{}
Namespaces are the global objects a script sees, with the Go values behind them; the script documentation in docs/scripts is generated from their methods.
func RemoveScriptInputs ¶
Types ¶
type DeviceGroupSelection ¶
type DeviceGroupSelection struct {
Id string `json:"id"`
}
type DeviceSelection ¶
type GenericEventSource ¶
type ImportSelection ¶
type IotOption ¶
type IotOption struct {
DeviceSelection *DeviceSelection `json:"device_selection,omitempty"`
DeviceGroupSelection *DeviceGroupSelection `json:"device_group_selection,omitempty"`
ImportSelection *ImportSelection `json:"import_selection,omitempty"`
GenericEventSource *GenericEventSource `json:"generic_event_source,omitempty"`
}
func GetDevicesWithService ¶
func GetDevicesWithService(ctx context.Context, iotClient client.Interface, token string, entity IotOption, criteria []devicemodel.FilterCriteria) (result []IotOption, err error)
type ScriptEnv ¶
type ScriptEnv struct {
Variables map[string]interface{}
VariablesUpdates map[string]interface{}
Inputs map[string]interface{}
// the variables of the instance when the task began, which inputs.get falls back to
InstanceVariables map[string]interface{}
Outputs map[string]interface{}
// contains filtered or unexported fields
}
ScriptEnv is what a script sees: the variables of the instance, the inputs and outputs of the task, the device repository and helpers, all with the rights of the user.
func NewScriptEnv ¶
type ScriptEnvConsole ¶
type ScriptEnvConsole struct {
// contains filtered or unexported fields
}
func NewConsoleScriptEnv ¶
func NewConsoleScriptEnv(env *ScriptEnv) *ScriptEnvConsole
func (*ScriptEnvConsole) Dump ¶
func (this *ScriptEnvConsole) Dump()
Dump writes all smart-service instance variables, the variables changed by this script, process worker inputs and process worker outputs known at the time of the call to the worker log
func (*ScriptEnvConsole) Log ¶
func (this *ScriptEnvConsole) Log(args ...interface{})
Log writes the arguments, separated by spaces, as info message to the worker log; strings are written as they are, everything else as json
type ScriptEnvDeviceRepo ¶
type ScriptEnvDeviceRepo struct {
// contains filtered or unexported fields
}
func NewDeviceRepoScriptEnv ¶
func NewDeviceRepoScriptEnv(env *ScriptEnv) *ScriptEnvDeviceRepo
func (*ScriptEnvDeviceRepo) GetAspect ¶
func (this *ScriptEnvDeviceRepo) GetAspect(id string) models.Aspect
func (*ScriptEnvDeviceRepo) GetAspectNode ¶
func (this *ScriptEnvDeviceRepo) GetAspectNode(id string) models.AspectNode
func (*ScriptEnvDeviceRepo) GetAspectNodes ¶
func (this *ScriptEnvDeviceRepo) GetAspectNodes() []models.AspectNode
func (*ScriptEnvDeviceRepo) GetAspectNodesByIdList ¶
func (this *ScriptEnvDeviceRepo) GetAspectNodesByIdList(ids []string) []models.AspectNode
func (*ScriptEnvDeviceRepo) GetAspectNodesMeasuringFunctions ¶
func (*ScriptEnvDeviceRepo) GetAspectNodesWithMeasuringFunction ¶
func (this *ScriptEnvDeviceRepo) GetAspectNodesWithMeasuringFunction(ancestors bool, descendants bool) []models.AspectNode
func (*ScriptEnvDeviceRepo) GetAspects ¶
func (this *ScriptEnvDeviceRepo) GetAspects() []models.Aspect
func (*ScriptEnvDeviceRepo) GetAspectsWithMeasuringFunction ¶
func (this *ScriptEnvDeviceRepo) GetAspectsWithMeasuringFunction(ancestors bool, descendants bool) []models.Aspect
func (*ScriptEnvDeviceRepo) GetCharacteristic ¶
func (this *ScriptEnvDeviceRepo) GetCharacteristic(id string) models.Characteristic
func (*ScriptEnvDeviceRepo) GetConceptWithCharacteristics ¶
func (this *ScriptEnvDeviceRepo) GetConceptWithCharacteristics(id string) models.ConceptWithCharacteristics
func (*ScriptEnvDeviceRepo) GetConceptWithoutCharacteristics ¶
func (this *ScriptEnvDeviceRepo) GetConceptWithoutCharacteristics(id string) models.Concept
func (*ScriptEnvDeviceRepo) GetDeviceClass ¶
func (this *ScriptEnvDeviceRepo) GetDeviceClass(id string) models.DeviceClass
func (*ScriptEnvDeviceRepo) GetDeviceClasses ¶
func (this *ScriptEnvDeviceRepo) GetDeviceClasses() []models.DeviceClass
func (*ScriptEnvDeviceRepo) GetDeviceClassesControllingFunctions ¶
func (this *ScriptEnvDeviceRepo) GetDeviceClassesControllingFunctions(id string) []models.Function
func (*ScriptEnvDeviceRepo) GetDeviceClassesFunctions ¶
func (this *ScriptEnvDeviceRepo) GetDeviceClassesFunctions(id string) []models.Function
func (*ScriptEnvDeviceRepo) GetDeviceClassesWithControllingFunctions ¶
func (this *ScriptEnvDeviceRepo) GetDeviceClassesWithControllingFunctions() []models.DeviceClass
func (*ScriptEnvDeviceRepo) GetDeviceTypeSelectables ¶
func (this *ScriptEnvDeviceRepo) GetDeviceTypeSelectables(query []model.FilterCriteria, pathPrefix string, includeModified bool, servicesMustMatchAllCriteria bool) []model.DeviceTypeSelectable
func (*ScriptEnvDeviceRepo) GetFunction ¶
func (this *ScriptEnvDeviceRepo) GetFunction(id string) models.Function
func (*ScriptEnvDeviceRepo) GetFunctionsByType ¶
func (this *ScriptEnvDeviceRepo) GetFunctionsByType(rdfType string) []models.Function
func (*ScriptEnvDeviceRepo) GetLeafCharacteristics ¶
func (this *ScriptEnvDeviceRepo) GetLeafCharacteristics() []models.Characteristic
func (*ScriptEnvDeviceRepo) GetLocation ¶
func (this *ScriptEnvDeviceRepo) GetLocation(id string) models.Location
func (*ScriptEnvDeviceRepo) GetService ¶
func (this *ScriptEnvDeviceRepo) GetService(id string) models.Service
func (*ScriptEnvDeviceRepo) ListDeviceTypes ¶
func (this *ScriptEnvDeviceRepo) ListDeviceTypes(limit int64, offset int64, sort string, filter []model.FilterCriteria, includeModified bool, includeUnmodified bool) []models.DeviceType
func (*ScriptEnvDeviceRepo) ListHubDeviceIds ¶
func (this *ScriptEnvDeviceRepo) ListHubDeviceIds(id string, asLocalId bool) []string
func (*ScriptEnvDeviceRepo) ReadDevice ¶
func (this *ScriptEnvDeviceRepo) ReadDevice(id string) models.Device
func (*ScriptEnvDeviceRepo) ReadDeviceByLocalId ¶
func (this *ScriptEnvDeviceRepo) ReadDeviceByLocalId(localId string) models.Device
func (*ScriptEnvDeviceRepo) ReadDeviceGroup ¶
func (this *ScriptEnvDeviceRepo) ReadDeviceGroup(id string) models.DeviceGroup
func (*ScriptEnvDeviceRepo) ReadDeviceType ¶
func (this *ScriptEnvDeviceRepo) ReadDeviceType(id string) models.DeviceType
type ScriptEnvInputs ¶
type ScriptEnvInputs struct {
// contains filtered or unexported fields
}
func NewInputsScriptEnv ¶
func NewInputsScriptEnv(env *ScriptEnv) *ScriptEnvInputs
func (*ScriptEnvInputs) Exists ¶
func (this *ScriptEnvInputs) Exists(name string) bool
Exists checks if a process worker input or a variable of the instance exists
func (*ScriptEnvInputs) Get
deprecated
func (this *ScriptEnvInputs) Get(name string) interface{}
Get value of a process worker input; a name that is no input of the task finds the variable of the instance, e.g. a start parameter
Deprecated: use getValue, which returns selections and lists as values instead of JSON text
func (*ScriptEnvInputs) GetValue ¶ added in v0.10.0
func (this *ScriptEnvInputs) GetValue(name string) interface{}
GetValue returns a process worker input or a variable of the instance as a value: JSON text of an object or a list, as IoT and multiple selections arrive, becomes that object or list, also in each element of a list; other values stay as they are
func (*ScriptEnvInputs) List ¶
func (this *ScriptEnvInputs) List() []interface{}
List input values sorted by their names
func (*ScriptEnvInputs) ListNames ¶
func (this *ScriptEnvInputs) ListNames() []string
ListNames lists sorted input names
type ScriptEnvOutputs ¶
type ScriptEnvOutputs struct {
// contains filtered or unexported fields
}
func NewOutputsScriptEnv ¶
func NewOutputsScriptEnv(env *ScriptEnv) *ScriptEnvOutputs
func (*ScriptEnvOutputs) Get ¶
func (this *ScriptEnvOutputs) Get(name string) interface{}
Get a process worker output
func (*ScriptEnvOutputs) Set ¶
func (this *ScriptEnvOutputs) Set(name string, value interface{})
Set a process worker output
func (*ScriptEnvOutputs) SetJson
deprecated
func (this *ScriptEnvOutputs) SetJson(name string, value interface{})
SetJson marshals the given value to json and sets it as a process worker output
Deprecated: use set; the engine keeps values as they are, Camunda needed the JSON text
type ScriptEnvUtil ¶
type ScriptEnvUtil struct {
// contains filtered or unexported fields
}
func NewScriptEnvUtil ¶
func NewScriptEnvUtil(env *ScriptEnv) *ScriptEnvUtil
func (*ScriptEnvUtil) GetDevicesWithServiceFromEntityString
deprecated
func (this *ScriptEnvUtil) GetDevicesWithServiceFromEntityString(entityStr string, criteria []devicemodel.FilterCriteria) []IotOption
GetDevicesWithServiceFromEntityString finds a list of iot-options where the entity is the same the input, but the Service field is set with those that match the input criteria
Deprecated: use getDevicesWithServiceFromIotOption with the option as a value, e.g. from inputs.getValue
func (*ScriptEnvUtil) GetDevicesWithServiceFromIotOption ¶
func (this *ScriptEnvUtil) GetDevicesWithServiceFromIotOption(entity IotOption, criteria []devicemodel.FilterCriteria) []IotOption
GetDevicesWithServiceFromIotOption finds a list of iot-options where the entity is the same the input, but the Service field is set with those that match the input criteria
func (*ScriptEnvUtil) GetUserId ¶
func (this *ScriptEnvUtil) GetUserId() string
GetUserId returns the user-id of the executing user
func (*ScriptEnvUtil) GetUserToken ¶
func (this *ScriptEnvUtil) GetUserToken() string
GetUserToken returns a jwt-token for the executing user
func (*ScriptEnvUtil) GroupIotOptionsByDevice ¶
func (this *ScriptEnvUtil) GroupIotOptionsByDevice(entities []IotOption) map[string][]IotOption
GroupIotOptionsByDevice groups a list of IotOption by their device id; options that are not devices will be grouped under ""
func (*ScriptEnvUtil) GroupIotOptionsByService ¶
func (this *ScriptEnvUtil) GroupIotOptionsByService(entities []IotOption) map[string][]IotOption
GroupIotOptionsByService groups a list of IotOption by their service id; options that are not devices or dont hav a service-id will be grouped under ""
func (*ScriptEnvUtil) IsDeviceGroupIotOption ¶
func (this *ScriptEnvUtil) IsDeviceGroupIotOption(entity IotOption) bool
IsDeviceGroupIotOption checks if the input is a device-group
func (*ScriptEnvUtil) IsDeviceGroupIotOptionStr
deprecated
func (this *ScriptEnvUtil) IsDeviceGroupIotOptionStr(entityStr string) bool
IsDeviceGroupIotOptionStr checks if the input is a device-group
Deprecated: use isDeviceGroupIotOption with the option as a value, e.g. from inputs.getValue
func (*ScriptEnvUtil) IsDeviceIotOption ¶
func (this *ScriptEnvUtil) IsDeviceIotOption(entity IotOption) bool
IsDeviceIotOption checks if the input is a device
func (*ScriptEnvUtil) IsDeviceIotOptionStr
deprecated
func (this *ScriptEnvUtil) IsDeviceIotOptionStr(entityStr string) bool
IsDeviceIotOptionStr checks if the input is a device
Deprecated: use isDeviceIotOption with the option as a value, e.g. from inputs.getValue
func (*ScriptEnvUtil) IsImportIotOption ¶
func (this *ScriptEnvUtil) IsImportIotOption(entity IotOption) bool
IsImportIotOption checks if the input is a import
func (*ScriptEnvUtil) IsImportIotOptionStr
deprecated
func (this *ScriptEnvUtil) IsImportIotOptionStr(entityStr string) bool
IsImportIotOptionStr checks if the input is a import
Deprecated: use isImportIotOption with the option as a value, e.g. from inputs.getValue
type ScriptEnvVariables ¶
type ScriptEnvVariables struct {
// contains filtered or unexported fields
}
func NewVariablesScriptEnv ¶
func NewVariablesScriptEnv(env *ScriptEnv) *ScriptEnvVariables
func (*ScriptEnvVariables) DerefName ¶
func (this *ScriptEnvVariables) DerefName(ref string) string
DerefName returns the name of a smart-service instance variable referenced in parameter ref
func (*ScriptEnvVariables) DerefTemplate ¶
func (this *ScriptEnvVariables) DerefTemplate(templ string) string
DerefTemplate replaces variable references in the input string with the corresponding variable values
func (*ScriptEnvVariables) DerefValue ¶
func (this *ScriptEnvVariables) DerefValue(ref string) interface{}
DerefValue returns the value of a smart-service instance variable referenced in parameter ref
func (*ScriptEnvVariables) Exists ¶
func (this *ScriptEnvVariables) Exists(name string) bool
Exists checks if a smart-service instance variable exists
func (*ScriptEnvVariables) Read
deprecated
func (this *ScriptEnvVariables) Read(name string) interface{}
Read value of a smart-service instance variable
Deprecated: use readValue, which returns selections and lists as values instead of JSON text
func (*ScriptEnvVariables) ReadValue ¶ added in v0.10.0
func (this *ScriptEnvVariables) ReadValue(name string) interface{}
ReadValue returns a smart-service instance variable as a value: JSON text of an object or a list, as IoT and multiple selections arrive, becomes that object or list, also in each element of a list; other values stay as they are
func (*ScriptEnvVariables) Ref ¶
func (this *ScriptEnvVariables) Ref(name string) string
Ref creates a reference to a variable (e.g. "my_var_name" --> "{{.my_var_name}}") throws exception if variable is unknown
func (*ScriptEnvVariables) Write ¶
func (this *ScriptEnvVariables) Write(name string, value interface{})
Write value as smart-service instance variable
type Scripts ¶
type Scripts struct {
Logger *slog.Logger
Tokens TokenSource
Iot client.Interface
// scripts that ended the engine; nil blocks nothing (EXPR-03)
Blocklist *enginescript.Blocklist
}
Scripts runs the prescript or postscript inputs of a task, concatenated in the order of their names, within 2 seconds. Variables written by the script change in variables and are returned as changes; outputs extend the given ones.
func (Scripts) Run ¶
func (this Scripts) Run(ctx context.Context, userId string, prefix string, inputs map[string]interface{}, outputs map[string]interface{}, variables map[string]interface{}, instanceVariables map[string]interface{}) (variableChanges map[string]interface{}, result map[string]interface{}, err error)
Run runs the scripts with the given prefix; instanceVariables, which may be nil, are what inputs.get and inputs.exists find for a name that is no input of the task.
type TokenSource ¶
TokenSource returns a token of a user including the "Bearer " prefix.