diff --git a/forge/db/controllers/Device.js b/forge/db/controllers/Device.js index 4c6664d7c7..8c203d1c2f 100644 --- a/forge/db/controllers/Device.js +++ b/forge/db/controllers/Device.js @@ -166,6 +166,7 @@ module.exports = { result.push(makeVar('FF_SNAPSHOT_ID', snapshotId)) result.push(makeVar('FF_SNAPSHOT_NAME', snapshotName)) result.push(...app.db.controllers.Device.removePlatformSpecificEnvVars(envVars)) + return result }, diff --git a/forge/db/controllers/Project.js b/forge/db/controllers/Project.js index 56fe7a6bed..6d2e070f9e 100644 --- a/forge/db/controllers/Project.js +++ b/forge/db/controllers/Project.js @@ -270,6 +270,7 @@ module.exports = { result.push(makeVar('FF_PROJECT_ID', project.id || '', true)) // deprecated as of V1.6.0 result.push(makeVar('FF_PROJECT_NAME', project.name || '', true)) // deprecated as of V1.6.0 result.push(...app.db.controllers.Project.removePlatformSpecificEnvVars(envVars)) + return result }, @@ -485,7 +486,8 @@ module.exports = { sourceProjectEnvVars.forEach(envVar => { newProjectSettings.env.push({ name: envVar.name, - value: options.envVars === 'keys' ? '' : envVar.value + value: options.envVars === 'keys' ? '' : envVar.value, + hidden: envVar.hidden ?? false }) }) } diff --git a/forge/db/views/Project.js b/forge/db/views/Project.js index 2f4c4d28d1..7e381b8d65 100644 --- a/forge/db/views/Project.js +++ b/forge/db/views/Project.js @@ -82,7 +82,12 @@ module.exports = function (app) { result.launcherSettings.disableAutoSafeMode = disableAutoSafeMode.value } // Environment - result.settings.env = app.db.controllers.Project.insertPlatformSpecificEnvVars(proj, result.settings.env) + result.settings.env = app.db.controllers.Project.insertPlatformSpecificEnvVars(proj, result.settings.env).map((env) => { + if (Object.hasOwnProperty.call(env, 'hidden') && env.hidden === true) { + env.value = '' + } + return env + }) if (!result.settings.palette?.modules) { // If there are no modules listed in settings, check the StorageSettings // for the project to see what Node-RED may already think is installed diff --git a/forge/routes/api/device.js b/forge/routes/api/device.js index e90e183714..8eff12beed 100644 --- a/forge/routes/api/device.js +++ b/forge/routes/api/device.js @@ -718,6 +718,12 @@ module.exports = async function (app) { } }, async (request, reply) => { const settings = await request.device.getAllSettings() + settings.env = settings.env.map((env) => { + if (Object.hasOwnProperty.call(env, 'hidden') && env.hidden === true) { + env.value = '' + } + return env + }) if (request.teamMembership?.role === Roles.Owner) { reply.send(settings) } else { diff --git a/forge/routes/api/project.js b/forge/routes/api/project.js index 46bdc75f94..9fb6b6614c 100644 --- a/forge/routes/api/project.js +++ b/forge/routes/api/project.js @@ -411,6 +411,17 @@ module.exports = async function (app) { // Merge the settings into the existing values const currentProjectSettings = await request.project.getSetting(KEY_SETTINGS) || {} + if (newSettings.env && Array.isArray(newSettings.env)) { + newSettings.env = newSettings.env.map(env => { + // hidden env vars are received as empty strings so we'll replace the empty string with the previous value, + // allowing them to be overwritten when needed + if (Object.prototype.hasOwnProperty.call(env, 'hidden') && env.hidden && !env.value.length) { + const previousValue = currentProjectSettings.env.find(e => e.name === env.name) + env.value = previousValue.value + } + return env + }) + } const updatedSettings = app.db.controllers.ProjectTemplate.mergeSettings(currentProjectSettings, newSettings) changesToPersist.settings = { from: currentProjectSettings, to: updatedSettings } diff --git a/frontend/src/pages/admin/Template/sections/Environment.vue b/frontend/src/pages/admin/Template/sections/Environment.vue index 5239df8ddb..8edf4d6468 100644 --- a/frontend/src/pages/admin/Template/sections/Environment.vue +++ b/frontend/src/pages/admin/Template/sections/Environment.vue @@ -1,5 +1,5 @@