router icon indicating copy to clipboard operation
router copied to clipboard

add support for accessing environment variables from rhai scripts

Open garypen opened this issue 2 years ago • 1 comments

It would be helpful to provide access to ENV variables to rhai scripts.

garypen avatar Sep 12 '22 09:09 garypen

When we get round to this we need to ensure that we are using environment variable safe-listing mechanism that we are going to introduce for config expansion.

BrynCooke avatar Sep 12 '22 09:09 BrynCooke

Hi!

Any news about this subjetc? This is blocking for us.

Thks !

edriwing avatar Feb 15 '23 13:02 edriwing

Would it be practical to allow users to declare a "global_variables" key in the rhai yml configuration, where people could add their keys / values before they deploy, and we would load them once at router startup / config reload?

This would allow users to use variable expansion for env variables and more if they need to, and this would give narrower (and predeclared) access to variables to script writers.

eg:

rhai:
  scripts: "/rhai/scripts/directory"
  main: "test.rhai"
  global_variables:
    - foo: "bar"
    - baz: "${env.BAZ}"

would provide rhai script users with


let foo = Router.GLOBAL_VARIABLES.foo;
let baz = Router.GLOBAL_VARIABLES.baz;

As an important constraint, this must respect the environment variable that limits env-access by prefix.

This would remove this need as well

o0Ignition0o avatar May 26 '23 07:05 o0Ignition0o

Possibly, but not sure that adding a layer if indirection (plus config) would actually make things simpler. The existing env prefix stuff is pretty simple, so would be tempted to stick with that.

BrynCooke avatar May 26 '23 13:05 BrynCooke