Skip to content

Script Management Service

Summary

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

Operations

Name Tag Summary
scripts.sandbox() Sandbox Execute a Lua script string in a sandbox environment
scripts.trigger() Trigger Trigger an event from the active solution.

Events

Name Summary
* Custom event definition

Operations

sandbox

Description

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

Name Type Description
script string Script content which want to be executed
timeout integer 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

  • Returns {object} for Returned data from script execution

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

    Error response {object}

    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

Description

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

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

  • Returns number*, *string*, *object*, *array*, *null for Execution result

  • Returns nil for Asynchronously events triggered. No body data is returned

  • Returns {object} when Core service cannot use broadcast

    Error response {object}

    Name Type Description
    type string Error type
    error string Error message
    status integer Response code
  • Returns {object} when Service not found

    Error response {object}

    Name Type Description
    type string Error type
    error string Error message
    status integer Response code
  • Returns {object} when Standard http responses

    Error response {object}

    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

*

Description

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

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