mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add readOnly setting to prevent file writes in localfilesystem storage
This commit is contained in:
parent
1054193298
commit
4eb5058e68
@ -132,9 +132,11 @@ var localfilesystem = {
|
|||||||
settings.userDir = process.env.NODE_RED_HOME;
|
settings.userDir = process.env.NODE_RED_HOME;
|
||||||
} else {
|
} else {
|
||||||
settings.userDir = fspath.join(process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE || process.env.NODE_RED_HOME,".node-red");
|
settings.userDir = fspath.join(process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE || process.env.NODE_RED_HOME,".node-red");
|
||||||
|
if (!settings.readOnly) {
|
||||||
promises.push(promiseDir(settings.userDir));
|
promises.push(promiseDir(settings.userDir));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (settings.flowFile) {
|
if (settings.flowFile) {
|
||||||
flowsFile = settings.flowFile;
|
flowsFile = settings.flowFile;
|
||||||
@ -178,7 +180,9 @@ var localfilesystem = {
|
|||||||
|
|
||||||
globalSettingsFile = fspath.join(settings.userDir,".config.json");
|
globalSettingsFile = fspath.join(settings.userDir,".config.json");
|
||||||
|
|
||||||
|
if (!settings.readOnly) {
|
||||||
promises.push(promiseDir(libFlowsDir));
|
promises.push(promiseDir(libFlowsDir));
|
||||||
|
}
|
||||||
|
|
||||||
return when.all(promises);
|
return when.all(promises);
|
||||||
},
|
},
|
||||||
@ -201,6 +205,10 @@ var localfilesystem = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
saveFlows: function(flows) {
|
saveFlows: function(flows) {
|
||||||
|
if (settings.readOnly) {
|
||||||
|
return when.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
if (fs.existsSync(flowsFullPath)) {
|
if (fs.existsSync(flowsFullPath)) {
|
||||||
fs.renameSync(flowsFullPath,flowsFileBackup);
|
fs.renameSync(flowsFullPath,flowsFileBackup);
|
||||||
}
|
}
|
||||||
@ -238,6 +246,10 @@ var localfilesystem = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
saveCredentials: function(credentials) {
|
saveCredentials: function(credentials) {
|
||||||
|
if (settings.readOnly) {
|
||||||
|
return when.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
if (fs.existsSync(credentialsFile)) {
|
if (fs.existsSync(credentialsFile)) {
|
||||||
fs.renameSync(credentialsFile,credentialsFileBackup);
|
fs.renameSync(credentialsFile,credentialsFileBackup);
|
||||||
}
|
}
|
||||||
@ -268,6 +280,9 @@ var localfilesystem = {
|
|||||||
return when.resolve({});
|
return when.resolve({});
|
||||||
},
|
},
|
||||||
saveSettings: function(settings) {
|
saveSettings: function(settings) {
|
||||||
|
if (settings.readOnly) {
|
||||||
|
return when.resolve();
|
||||||
|
}
|
||||||
return writeFile(globalSettingsFile,JSON.stringify(settings,null,1));
|
return writeFile(globalSettingsFile,JSON.stringify(settings,null,1));
|
||||||
},
|
},
|
||||||
getSessions: function() {
|
getSessions: function() {
|
||||||
@ -288,6 +303,9 @@ var localfilesystem = {
|
|||||||
return when.resolve({});
|
return when.resolve({});
|
||||||
},
|
},
|
||||||
saveSessions: function(sessions) {
|
saveSessions: function(sessions) {
|
||||||
|
if (settings.readOnly) {
|
||||||
|
return when.resolve();
|
||||||
|
}
|
||||||
return writeFile(sessionsFile,JSON.stringify(sessions));
|
return writeFile(sessionsFile,JSON.stringify(sessions));
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -335,6 +353,9 @@ var localfilesystem = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
saveLibraryEntry: function(type,path,meta,body) {
|
saveLibraryEntry: function(type,path,meta,body) {
|
||||||
|
if (settings.readOnly) {
|
||||||
|
return when.resolve();
|
||||||
|
}
|
||||||
var fn = fspath.join(libDir, type, path);
|
var fn = fspath.join(libDir, type, path);
|
||||||
var headers = "";
|
var headers = "";
|
||||||
for (var i in meta) {
|
for (var i in meta) {
|
||||||
|
Loading…
Reference in New Issue
Block a user