Ok, maybe I'm thinking this the wrong way but here's what I want to do.
I have an undefined number of home automation controllers, accessible via HTTP requests (i.e. if you want to turn on a lamp you send an HTTP request to the controller linked to the lamp). It's using basic authentification.
I'd like to access those controllers using Node-Red via HTTP IN requests using a GET/POST parameter to specifiy which Home Controller you want to access. I want to users of the Node-red app to use the Node-red interface and not fiddle with internal JS code.
So I was thinking I could create a custom Config Node to hold each controller config (Name, IP, port, credentials) and then either a Function Node or another custom node to select the appropriate Controller, based on the name passed as a parameter and then send the request to the controller.
Node-red would receive a request like
the custom node or Function node would parse all the Controllers Config Nodes to find the necessary info linked with "CTRL1" and send this as a payload to a HTTP Request node (although there is probably a problem with the credentials which are specified inside the HTTP Request Node and cannot use mustache).
HTTP IN --> Function to find config node for controller name as stored in the "controller" param and prepare a payload for the request --> HTTP REQUEST
If config nodes were accessible as a context, the function Node would look something like.
var configs = config.get('controller-type'); // would return an array of all the configs of type "controller-type"
for (i= 0;i<configs.length;i++) {
if (configs[i].name == msg.payload.controller) break;
}
controller_config = configs[i];
// prepare the payload for the http request ...
As a workaround I thought about using the global context and maybe node-red-contrib-config but since the Config Nodes' purpose is to hold a Config, it seemed more in-key with NR philosophy.