Skip to content

thinx-cloud/transformer

Repository files navigation

thinx-node-transformer

pipeline status Quality Gate Status Coverage Status Codacy Badge

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

  1. Register at Rollbar.io and your Access Token as POST_SERVER_ITEM_ACCESS_TOKEN environment variable named ROLLBAR_ACCESS_TOKEN with optional ROLLBAR_ENVIRONMENT tag See example expected code at THiNX Wiki

Exceptionally dumb

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.

Security Note

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).

Supported Modules (Public)

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

Notes

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

Building the container

docker build -t suculent/thinx-node-transformer .

Job Request Format

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"
          }
        }
    }
  ]
}

About

Containerized NodeJS executor for THiNX

Resources

License

Stars

Watchers

Forks

Packages

No packages published