Run a private task before the nodered service is started ?
Launch a script when using the Deploy button ?
For the 1st case, we can obviously create a script that does the private task and then launches node-red-start. But maybe there is already something integrated in NR ?
For the 2nd case, I don't see how to do it, any ideas?
Is that a long running service that you want to start before the node-red service starts? If so then you can build that requirement into the systemd startup script (assuming this is on a system that uses systemd, such as Raspbian or Ubuntu). Make a systemd script to start the service and then require that in the node red systemd script.
Another possibility is to use an exec node to run the script and trigger that from an Inject node set to fire on startup, but that may be too late for your requirement.
Thank you Colin for your thoughts.
The idea behind this is the following.
I want to "somewhat" protect my flows from being stolen.
I imagine encrypting my flows with OpenSSL into a script and decrypting them before NR reads them, once NR starts, launch an exec node that re-encrypts those same flows.
Also for the Deploy, I would like to have an automatic encryption once the flows are written and saved in the .json. This point is the least important.
The mechanics are not yet finalized, but it's the idea that if the map is stolen, it's not so easy to read the json file with a simple editor.
You will also have to find the decryption key. Not everything is accessible at once.
I seem to remember reading that the filing system in node-red is pluggable, so one could replace that with your encrypt/decrypt code, but perhaps my memory is just of an intention to make it pluggable. Someone more knowledgeable would have to comment on that.
Yes, absolutely. Colin has given one suggestion but another would be to put the task into Node-RED's settings.js file above the exports line. I do this regularly to capture some information that I want to be able to use later. That information can be fed into Node-RED flows via the globals property in the settings.
Yes, this is possible too. But in this case, you need a custom node.
Very interesting to be able to link everything from NR and not outside.
When you say above the part *module.exports = * is it the place where for example I can define a variable? process.env.test = "blabla";
What would be the format to launch a shell named for example decrypt.sh?
On the command line it is: sh decrypt.sh
Will NR launch the script synchronously to make sure that it can read the json files
The plugable storage linked to by @TotallyInformation must surely be the way to go. Then you can encrypt it there and don't need to worry about anything else.
Here I must say that I did not understand, it is completely beyond my knowledge.
Are they talking about storage
it must have another meaning in English.
You may need to read up a little on node.js apps and how they work. The settings.js file is actually a node.js module that is loaded by Node-RED as it starts up.
Anything above (technically anything outside) the extports object is run before the export and any stored values will not be available to Node-RED unless you shove them into the exports section. That's what the globals property is there for, it exposes whatever you put in it as a global variable in Node-RED.
In your case, you might be able to decrypt the file there but you would have to try it as I don't know exactly where Node-RED reads the json file.
As Colin says, you will almost certainly be better off working with the Custom Storage Module approach.
Yes, disc (or whatever) storage for flows etc. It is possible to replace the code that node-red uses to write to disc storage, with your own code. If you do that then you can decrypt the flow file before passing it to node-red and you can encrypt when node-red gives it to you to save.
I understand the idea of putting code there, I've read a lot of articles but for me it's like looking for something I don't know in the fog. Not easy
I didn't know Node.js before I discovered NR.
What I'm thinking of doing is just a script at startup that decrypts the files and then runs NR.
Thanks for the advice though.
Would it be possible to show me one or two examples of actions taken before the launch of NR.
And the associated code used in the settings.js file.
This will help me to get on the right track.
Thanks for your help
/JL