Script Management Service

This service provides functionality related to the scripting environment including usefull features such as sandbox execution & triggering your own solution event.

Operations

Sandbox
Trigger

Events


Operations

sandbox

Execute a Lua script as a string and return the execution result. No Murano service calls or log print is Max execution time is 10 seconds.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
script string Script content which want to be executed
timeout integer {1..10} CPU timeout in seconds
Default: 1
parameters object, string, array, number, boolean The parameters passed to the script execution accessible in the "parameters".
If the provided parameters is an object, the sub-keys are also directly accessible by they name.

Responses

Returned data from script execution

Content: object

Name Type Description
value number, object, string, boolean, array, null Value returned by the script execution
Standard http responses

Content: object Error response

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local result = Scripts.sandbox({
  script = "return a + b",
  parameters = {
    a = 1,
    b = 2
  }
})
print(result.value == 3)

trigger

Trigger an event from the active solution. The execution mode can be either:

  • sync (default): This is a blocking call and the result of the execution is returned.
  • async: The event is executed asynchronously. No result is returned.

Tips: You can define custom event under this service.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
service ^(?![0-9])[a-zA-Z0-9]{2,63}$ Indicates the service to trigger by specifying the service alias. By default target this very service, as it allows custom events which would not get trigger by other mean.
Default: "scripts"
event ^(?![0-9])[a-zA-Z0-9]{2,63}$ Indicates the event to trigger. Refer to Murano Service documentation regarding the available events for each service. You can also defined event un-related to any other service by defining custom event under this service.
mode "sync", "async" Indicate the execution mode, blocking or asynchronously.
Default: "sync"
data number, string, object, array, null Parameter object transmitted to the subscribers event handler function.

Responses

Execution result

Content: number, string, object, array, null

Asynchronously events triggered. No body data is returned

Content: nil

Core service cannot use broadcast

Content: object Error response

Name Type Description
type string Error type
error string Error message
status integer Response code
Service not found

Content: object Error response

Name Type Description
type string Error type
error string Error message
status integer Response code
Standard http responses

Content: object Error response

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

-- Trigger custom events asynchronously
Scripts.trigger({event="task1", mode="async"}) Scripts.trigger({event="task2", mode="async"})
-- Simulating a service event and return the execution value.
local eventData = {service="webservice", event="request", data={method="GET", route="/index"}} local response = Scripts.trigger(eventData)


Events

*

User can define custom event with dynamic name for this service. Those event can only be triggered using the 'trigger' operation of this service. An eventHandler have to be created for each supported operations.

Arguments

data - object - The event trigger parameters
Name Type Description

Example

-- User define a custom task1 event handler
function handle_scripts_task1 (data)

  -- Some behavior. The returned response is only useful for blocking calls

  return responseData
end