router
router copied to clipboard
add support for accessing environment variables from rhai scripts
It would be helpful to provide access to ENV variables to rhai scripts.
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.
Hi!
Any news about this subjetc? This is blocking for us.
Thks !
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
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.