Purpose of this service is to provide sandboxed execution environment for JavaScript lambda functions in THiNX (called Transformers, as they are used to transform and process proprietary device states).
Instance of NodeJS process thinx-node-transformer safely enclosed inside a docker image. Takes jobs as HTTP posts and executes JavaScript code from job locally.
Before first run
- Register at Rollbar.io and your Access Token as
POST_SERVER_ITEM_ACCESS_TOKEN
environment variable namedROLLBAR_ACCESS_TOKEN
with optionalROLLBAR_ENVIRONMENT
tag See example expected code at THiNX Wiki
This instance does not support anything more than bare node.js express server with https support. Please, ask for required extensions or provide PR with usage example.
In production, it's advised to track your Transformer using Rollbar as implemented in example.
First of all, generate your own Rollbar token, or remove the Rollbar implementation if you don't want to track what's going on inside your Transformer.
This instance must be firewalled. Must not be accessible except on localhost, where it is expected to execute primitive JavaScript in sandbox. Expected to run in Docker as a non-root user. Supports outgoing HTTPS.
**There's plan to implement outbound SSL sockets instead of incoming HTTP REST API (similar way to thinxcloud/worker project).
Feel free to submit proposals for adding more modules. Intention is to keep it small and safe.
base-64
: processed JavaScript must be safely encoded when transferred
ssl-root-cas
: https support
Instance should accept only local HTTP requests. Make sure neither port 7474 is exposed on host machine firewall.
docker run \
--user=transformer \
-e ROLLBAR_ACCESS_TOKEN=<your-rollbar-token> \
-d -p 7474 \
-v /var/logs:/logs \
-v /$(pwd):/app \
suculent/thinx-node-transformer
docker build -t suculent/thinx-node-transformer .
HTTP POST BODY:
{
jobs: [
{
id: "transaction-identifier",
owner: "owner-id",
codename: "status-transformer-alias",
code: base64.encode("function transformer(status, device) { return status; };"),
params: {
status: "Battery 100.0V",
device: {
owner: "owner-id",
id: "device-id"
}
}
}
]
}