Documentation
¶
Index ¶
- Constants
- Variables
- func NewLuaEnv(service *rulesService, script *LuaScript, message *protomfx.Message, ...) (*luaEnv, error)
- type Action
- type Condition
- type LuaScript
- type LuaScriptsPage
- type Repository
- type RepositoryRules
- type RepositoryScripts
- type Rule
- type RulesPage
- type ScriptRun
- type ScriptRunsPage
- type Service
- type ServiceRules
- type ServiceScripts
Constants ¶
View Source
const ( ScriptRunStatusSuccess = "success" ScriptRunStatusFail = "fail" )
View Source
const ( ActionTypeSMTP = "smtp" ActionTypeSMPP = "smpp" ActionTypeAlarm = "alarm" OperatorAND = "AND" OperatorOR = "OR" )
Variables ¶
View Source
var ErrScriptSize = errors.New("script size exceeds limit")
Functions ¶
func NewLuaEnv ¶ added in v0.38.0
func NewLuaEnv(service *rulesService, script *LuaScript, message *protomfx.Message, payload map[string]any, functions ...luaAPIFunc) (*luaEnv, error)
Initializes and returns a new script environment associated with a specific Lua script and Mainflux message. The following is made available to the Lua environment as part of an "mfx" table in the global namespace:
- The associated Message payload, subtopic, creation timestamp, and publisher ID
- API functions
Types ¶
type LuaScript ¶ added in v0.38.0
type LuaScript struct {
ID string
GroupID string
// Lua script content
Script string
Name string
Description string
}
LuaScript represents a specific Lua script.
type LuaScriptsPage ¶ added in v0.38.0
type Repository ¶ added in v0.38.0
type Repository interface {
RepositoryRules
RepositoryScripts
}
type RepositoryRules ¶ added in v0.38.0
type RepositoryRules interface {
// Save persists multiple rules. Rules are saved using a transaction.
// If one rule fails then none will be saved.
// Successful operation is indicated by a non-nil error response.
Save(ctx context.Context, rules ...Rule) ([]Rule, error)
// RetrieveByID retrieves a rule having the provided ID.
RetrieveByID(ctx context.Context, id string) (Rule, error)
// RetrieveByThing retrieves rules assigned to a certain thing,
// identified by a given thing ID.
RetrieveByThing(ctx context.Context, thingID string, pm apiutil.PageMetadata) (RulesPage, error)
// RetrieveByGroup retrieves rules related to a certain group,
// identified by a given group ID.
RetrieveByGroup(ctx context.Context, groupID string, pm apiutil.PageMetadata) (RulesPage, error)
// RetrieveThingIDsByRule retrieves all thing IDs that have the given rule assigned.
RetrieveThingIDsByRule(ctx context.Context, ruleID string) ([]string, error)
// Update performs an update to the existing rule.
// A non-nil error is returned to indicate operation failure.
Update(ctx context.Context, r Rule) error
// Remove removes rules having the provided IDs.
Remove(ctx context.Context, ids ...string) error
// RemoveByGroup removes rules related to a certain group,
// identified by a given group ID.
RemoveByGroup(ctx context.Context, groupID string) error
// Assign assigns rules to the specified thing.
Assign(ctx context.Context, thingID string, ruleIDs ...string) error
// Unassign removes specific rule assignments from a given thing.
Unassign(ctx context.Context, thingID string, ruleIDs ...string) error
// UnassignByThing removes all rule assignments for a certain thing,
// identified by a given thing ID.
UnassignByThing(ctx context.Context, thingID string) error
}
type RepositoryScripts ¶ added in v0.38.0
type RepositoryScripts interface {
// SaveScripts persists multiple Lua scripts.
SaveScripts(ctx context.Context, scripts ...LuaScript) ([]LuaScript, error)
// RetrieveScriptByID retrieves a single Lua script denoted by ID.
RetrieveScriptByID(ctx context.Context, id string) (LuaScript, error)
// RetrieveScriptsByThing retrieves a list of Lua scripts assigned to a specific Thing.
RetrieveScriptsByThing(ctx context.Context, thingID string, pm apiutil.PageMetadata) (LuaScriptsPage, error)
// RetrieveScriptsByGroup retrieves a list of Lua scripts belonging to a specific Group.
RetrieveScriptsByGroup(ctx context.Context, groupID string, pm apiutil.PageMetadata) (LuaScriptsPage, error)
// RetrieveThingIDsByScript retrieves a list of Thing IDs to which the specific Lua script is assigned.
RetrieveThingIDsByScript(ctx context.Context, scriptID string) ([]string, error)
// UpdateScript updates the script denoted by script.ID.
UpdateScript(ctx context.Context, script LuaScript) error
// RemoveScripts removes Lua scripts with the provided ids.
RemoveScripts(ctx context.Context, ids ...string) error
// RemoveScriptsByGroup removes all Lua scripts belonging to a specific Group.
RemoveScriptsByGroup(ctx context.Context, groupID string) error
// AssignScripts assigns one or more Lua scripts to a specific Thing.
AssignScripts(ctx context.Context, thingID string, scriptIDs ...string) error
// Unassign unassgins one or more Lua scripts from a specific Thing.
UnassignScripts(ctx context.Context, thingID string, scriptIDs ...string) error
// UnassignScriptsFromThing unassigns all scripts from a specific Thing.
UnassignScriptsFromThing(ctx context.Context, thingID string) error
// SaveScriptRuns preserves multiple ScriptRuns.
SaveScriptRuns(ctx context.Context, runs ...ScriptRun) ([]ScriptRun, error)
// RetrieveScriptRunByID retrieves a single ScriptRun based on its ID.
RetrieveScriptRunByID(ctx context.Context, id string) (ScriptRun, error)
// RetrieveScriptRunsByThing retrieves a list of Script runs by Thing ID.
RetrieveScriptRunsByThing(ctx context.Context, thingID string, pm apiutil.PageMetadata) (ScriptRunsPage, error)
// RemoveScriptRuns removes one or more Script runs by IDs.
RemoveScriptRuns(ctx context.Context, ids ...string) error
}
type ScriptRun ¶ added in v0.38.0
type ScriptRun struct {
ID string
ScriptID string
ThingID string
Logs []string
StartedAt time.Time
FinishedAt time.Time
Status string
// Human-readable string representing a runtime error during the execution of the lua script. May be an empty string in case of no error.
Error string
// contains filtered or unexported fields
}
ScriptRun represents a specific run of a certain Lua script
type ScriptRunsPage ¶ added in v0.38.0
type Service ¶
type Service interface {
ServiceScripts
ServiceRules
consumers.Consumer
}
Service specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics). All methods that accept a token parameter use it to identify and authorize the user performing the operation.
func New ¶
func New(rules Repository, things protomfx.ThingsServiceClient, pubsub messaging.PubSub, idp uuid.IDProvider, logger logger.Logger, scriptsEnabled bool) Service
New instantiates the rules service implementation.
type ServiceRules ¶ added in v0.38.0
type ServiceRules interface {
// CreateRules creates rules.
CreateRules(ctx context.Context, token, groupID string, rules ...Rule) ([]Rule, error)
// ListRulesByThing retrieves a paginated list of rules by thing.
ListRulesByThing(ctx context.Context, token, thingID string, pm apiutil.PageMetadata) (RulesPage, error)
// ListRulesByGroup retrieves a paginated list of rules by group.
ListRulesByGroup(ctx context.Context, token, groupID string, pm apiutil.PageMetadata) (RulesPage, error)
// ListThingIDsByRule retrieves a list of thing IDs attached to the given rule ID.
ListThingIDsByRule(ctx context.Context, token, ruleID string) ([]string, error)
// ViewRule retrieves a specific rule by its ID.
ViewRule(ctx context.Context, token, id string) (Rule, error)
// UpdateRule updates the rule identified by the provided ID.
UpdateRule(ctx context.Context, token string, rule Rule) error
// RemoveRules removes the rules identified with the provided IDs.
RemoveRules(ctx context.Context, token string, ids ...string) error
// RemoveRulesByGroup removes the rules identified with the provided IDs.
RemoveRulesByGroup(ctx context.Context, groupID string) error
// AssignRules assigns rules to a specific thing.
AssignRules(ctx context.Context, token, thingID string, ruleIDs ...string) error
// UnassignRules removes rule assignments from a specific thing.
UnassignRules(ctx context.Context, token, thingID string, ruleIDs ...string) error
// UnassignRulesByThing removes all rule assignments from a specific thing.
UnassignRulesByThing(ctx context.Context, thingID string) error
}
type ServiceScripts ¶ added in v0.38.0
type ServiceScripts interface {
// CreateScripts persists multiple Lua scripts.
CreateScripts(ctx context.Context, token, groupID string, scripts ...LuaScript) ([]LuaScript, error)
// ListScriptsByThing retrieves a list of Scripts associated with a specific Thing.
ListScriptsByThing(ctx context.Context, token, thingID string, pm apiutil.PageMetadata) (LuaScriptsPage, error)
// ListScriptsByGroup retrieves a list of scripts belonging to a specific Group.
ListScriptsByGroup(ctx context.Context, token, groupID string, pm apiutil.PageMetadata) (LuaScriptsPage, error)
// ListThingIDsByScript retrieves a list of IDs of Things associated with a specific Script.
ListThingIDsByScript(ctx context.Context, token, scriptID string) ([]string, error)
// ViewScript retrieves a specific Script by its ID.
ViewScript(ctx context.Context, token, id string) (LuaScript, error)
// UpdateScript updates the Script identified by the provided ID.
UpdateScript(ctx context.Context, token string, script LuaScript) error
// RemoveScripts removes the Scripts identified by the provided IDs.
RemoveScripts(ctx context.Context, token string, ids ...string) error
// RemoveScriptsByGroup removes all Scripts belonging to a specific Group.
RemoveScriptsByGroup(ctx context.Context, groupID string) error
// AssignScripts assigns one or more Scripts to a specific Thing.
AssignScripts(ctx context.Context, token, thingID string, scriptIDs ...string) error
// UnassignScripts unassigns one or more scripts from a specific Thing.
UnassignScripts(ctx context.Context, token, thingID string, scriptIDs ...string) error
// UnassignScriptsFromThing unassigns all scripts from a specific Thing.
UnassignScriptsFromThing(ctx context.Context, thingID string) error
// ListScriptRunsByThing retrieves a list of Script Runs associated with a specific Thing.
ListScriptRunsByThing(ctx context.Context, token, thingID string, pm apiutil.PageMetadata) (ScriptRunsPage, error)
// RemoveScriptRuns removes the Runs identified by the provided IDs.
RemoveScriptRuns(ctx context.Context, token string, ids ...string) error
}
Click to show internal directories.
Click to hide internal directories.