How to check if cred encryption is turned off when using projects?

I am working on a little auth middleware experiment and I want to enforce some settings before enabling the middleware, such as https and cred encryption.

When not using projects, I can simply check if RED.settings.credentialSecret === false and reasonably assume that the creds are not encrypted due to the explicit setting.

When using projects, I cannot seem to find an api that can give me the info. Of course, I can check for the value manually to see if it is === false wrapped in a try/catch block in case the files don't exist:

const { projects, activeProject } = require(`${RED.settings.userDir}/.config.projects.json`);

const { credentialSecret } = projects[activeProject];
1 Like

Well, I found a different way using the runtime api. Of course, I would prefer if the project data was already available to the node, but it works just fine.

module.paths.push(process.env.NODE_RED_HOME);

const runtime = require('node_modules/@node-red/runtime');

runtime.projects.getActiveProject(process.env.USER)
  .then(project => {
    console.log(data.credentialSecret === false);
});

Requiring the node_modules/@node-red is loosely based on how ralphwetzel does it in node-red-mcu-plugin/mcu_plugin.js at main · ralphwetzel/node-red-mcu-plugin · GitHub, with the small change of pushing the path for require to find the global libs and then not need another dependency such as resolve-package-path.

1 Like

That's a nice move ... :+1:

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.