Home

Awesome

Environment variables for Macros published

Enhance your Webex Devices Macro runtime with environment variables:

Usage

Wait for the 'env-ready' event and load variables for local ENV:

note : there are multiple options when it comes to initializing a macro with ENV variables. Check the example folder for other coding styles and use cases.

const xapi = require('xapi');

// Wait for ENV variables to be accesible
xapi.on('env-ready', async (ready) => {

   const value = await getenv('DEVICE_SECRET');

   xapi.command('UserInterface Message Prompt Display', {
      Title: 'ENV',
      Text: `$DEVICE_SECRET = ${value}`,
      Duration: 10
   });
   
});

//
// ENV library
//   - getenv() function
//
...

Quickstart

  1. Deploy the environment macro to a device.

  2. Activate the 'environment' macro.

  3. Copy the env-ready macro to the device, and activate it too.

    You can pick either the minified or expanded version of 'env-ready'.

  4. Check the logs in the Macro Editor, you should see:

    08:22:00	[system]    Using XAPI transport: TSH
    08:22:00	[system]    Starting macros...
    08:22:00	environment Loading...
    08:22:00	getenv      Loading...
    08:22:02	getenv      Ready!
    08:22:02	environment Ready!
    08:22:02	environment'starting in persistent mode: environment variables are stored in the "ENV" macro.'
    08:22:03	getenv     'echo $DEVICE_SECRET = 1234'
    
  5. Congrats, your ENV is working!

    You can now copy the env-ready code snippet to an existing macro, and initialize your macro from the xapi.on('env-ready', async (ready) => { ... }) code block. Check the examples folder for inspiration.

    Note that if a variable is not found in ENV, an empty value is returned.

To go further

Architecture

Background information

When deploying CE customizations, one (or several combined) of the strategies below must be used to deal with secrets:

Architecture

Using a Pub/Sub pattern, macros can request environment variables from an 'Environment' macro, that can provide static , volative or persisted values.

macro_env

Design

This project uses the device local bus to enable communication across Macros.

local_bus

Moreover, the code uses several pattenrs to implement features not supported by CE:

Security concerns

The communications between the macros reading the ENV, and the 'environment' macro managing the ENV are send in clear text, via xCommand 'Message Send Text'.

As 'Message Send' events can be listened by code with an 'Integrator' role, this represents a potential vulnerability if secrets were to be stored in the env.

We recommend to enhance the security of your deployment by using one or both of: encrypted communications and encryption at rest.

Encrypted communications

The 'environment' macro and 'getenv()' function support encrypted communications.

Turn on the encrypted boolean both the 'environment' macro and 'getenv()' function to start seeing the message flying as encrypted.

A 'secret-based' and symetric encryption implementation is provided in the proposed implementation. Feel free to replace / enhance with a crypto algorithm that better meets your needs.

Encryption at rest

If secrets are to be stored, we recommend you encrypt these secrets before passing them to the environment.

Check the xapi-samples for examples of symetric and asymetric algorithms compatible with CE's macro runtime.