Config Variables Context
I'd like to add the ability to push config variables along with a Tessel script (addressing this Github issue). My design goal was to stay as consistent with Heroku and Node.js paradigms as possible. It seems like there are two use cases involved:
- Sending config variables for a specific script. This would be roughly identical to Heroku's config variables for keeping keys, passcodes, secrets, etc. separate from actual code.
- Setting config variables for all scripts ("global variables"). This would be useful for things like setting credentials for a proxy server that all network traffic should be routed through.
Global Config Variables
In terms of the software interface, I'm thinking the CLI could have an API for manipulating global variables (the same as Heroku's):
// Set a global config variable
tessel config:set VAR_KEY=VAR_VALUE
// Retrieve the value of a global config variable
tessel config:get [VAR_KEY] // If no key specified, it returns all
// Delete a config variable
tessel config:unset VAR_KEY
Single Script Config Variables
And to set config variables for single scripts, I figure we can either do something like the CLI commands above except with an extra flag or we can do something more simple/transparent like allowing a .json or .env file. I'm partial to the latter, specifically .env, because it's what I'm familiar with from using Node.
So my suggestion is a .env file in the root directory of a project where each local configuration variable is added:
In the case of conflicting variables between a globally set config variable and a locally set config variable, the locally set config variable with be passed on to the script.
You would be able to access these variables through the
process.env hash map within your script.
As an example, let's say I want all of my scripts to use the same Twilio authentication information:
tessel config:set TWILIO_KEY=12345678 TWILIO_SECRET=CLOSELY_HELD_SECRET
But I want this one specific project to be able to tell who's computer deployed it when I'm working in a team. I would make a file called
.env with the following contents and place it in the root directory:
I would be able to access these variables in my script like so:
console.log(process.env["TWILIO_KEY"]) // "12345678"
console.log(process.env["TWILIO_SECRET"]) // "CLOSELY_HELD_SECRET"
console.log(process.env["DEV_MACHINE"]) // "FRANK_LLOYD_WRIGHT
That's basically it. I would love feedback and suggestions on how to make this interaction more intuitive. I don't have a ton of prior experience with config variables so I'm sure this could be designed better. Just let me know!