mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge branch 'nodeSettings' into 0.17
This commit is contained in:
commit
e55933706d
@ -156,7 +156,7 @@
|
|||||||
clearNameData("ca");
|
clearNameData("ca");
|
||||||
});
|
});
|
||||||
|
|
||||||
if (RED.settings.tlsDisableLocalFiles) {
|
if (RED.settings.tlsConfigDisableLocalFiles) {
|
||||||
$("#node-config-row-uselocalfiles").hide();
|
$("#node-config-row-uselocalfiles").hide();
|
||||||
} else {
|
} else {
|
||||||
$("#node-config-row-uselocalfiles").show();
|
$("#node-config-row-uselocalfiles").show();
|
||||||
@ -178,7 +178,7 @@
|
|||||||
} else {
|
} else {
|
||||||
$("#node-config-input-ca").val("");
|
$("#node-config-input-ca").val("");
|
||||||
$("#node-config-input-cert").val("");
|
$("#node-config-input-cert").val("");
|
||||||
$("#node-config-input-key").val("");
|
$("#node-config-input-key").val("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -48,13 +48,13 @@ module.exports = function(RED) {
|
|||||||
this.valid = false;
|
this.valid = false;
|
||||||
this.error(err.toString());
|
this.error(err.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.credentials) {
|
if (this.credentials) {
|
||||||
var certData = this.credentials.certdata || "";
|
var certData = this.credentials.certdata || "";
|
||||||
var keyData = this.credentials.keydata || "";
|
var keyData = this.credentials.keydata || "";
|
||||||
var caData = this.credentials.cadata || "";
|
var caData = this.credentials.cadata || "";
|
||||||
|
|
||||||
if ((certData.length > 0) !== (keyData.length > 0)) {
|
if ((certData.length > 0) !== (keyData.length > 0)) {
|
||||||
this.valid = false;
|
this.valid = false;
|
||||||
this.error(RED._("tls.error.missing-file"));
|
this.error(RED._("tls.error.missing-file"));
|
||||||
@ -78,6 +78,12 @@ module.exports = function(RED) {
|
|||||||
certdata: {type:"text"},
|
certdata: {type:"text"},
|
||||||
keydata: {type:"text"},
|
keydata: {type:"text"},
|
||||||
cadata: {type:"text"}
|
cadata: {type:"text"}
|
||||||
|
},
|
||||||
|
settings: {
|
||||||
|
tlsConfigDisableLocalFiles: {
|
||||||
|
value: true,
|
||||||
|
exportable: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -52,6 +52,8 @@ module.exports = {
|
|||||||
safeSettings.editorTheme.palette = safeSettings.editorTheme.palette || {};
|
safeSettings.editorTheme.palette = safeSettings.editorTheme.palette || {};
|
||||||
safeSettings.editorTheme.palette.editable = false;
|
safeSettings.editorTheme.palette.editable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
settings.exportNodeSettings(safeSettings);
|
||||||
|
|
||||||
res.json(safeSettings);
|
res.json(safeSettings);
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,13 @@ function registerType(nodeSet,type,constructor,opts) {
|
|||||||
type = nodeSet;
|
type = nodeSet;
|
||||||
nodeSet = "";
|
nodeSet = "";
|
||||||
}
|
}
|
||||||
if (opts && opts.credentials) {
|
if (opts) {
|
||||||
credentials.register(type,opts.credentials);
|
if (opts.credentials) {
|
||||||
|
credentials.register(type,opts.credentials);
|
||||||
|
}
|
||||||
|
if (opts.settings) {
|
||||||
|
settings.registerNodeSettings(type,opts.settings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
registry.registerType(nodeSet,type,constructor);
|
registry.registerType(nodeSet,type,constructor);
|
||||||
}
|
}
|
||||||
|
@ -493,6 +493,7 @@ function enableNodeSet(typeOrId) {
|
|||||||
delete config.err;
|
delete config.err;
|
||||||
config.enabled = true;
|
config.enabled = true;
|
||||||
nodeConfigCache = null;
|
nodeConfigCache = null;
|
||||||
|
settings.enableNodeSettings(config.types);
|
||||||
return saveNodeList().then(function() {
|
return saveNodeList().then(function() {
|
||||||
return filterNodeInfo(config);
|
return filterNodeInfo(config);
|
||||||
});
|
});
|
||||||
@ -515,6 +516,7 @@ function disableNodeSet(typeOrId) {
|
|||||||
// TODO: persist setting
|
// TODO: persist setting
|
||||||
config.enabled = false;
|
config.enabled = false;
|
||||||
nodeConfigCache = null;
|
nodeConfigCache = null;
|
||||||
|
settings.disableNodeSettings(config.types);
|
||||||
return saveNodeList().then(function() {
|
return saveNodeList().then(function() {
|
||||||
return filterNodeInfo(config);
|
return filterNodeInfo(config);
|
||||||
});
|
});
|
||||||
|
@ -18,9 +18,12 @@ var when = require("when");
|
|||||||
var clone = require("clone");
|
var clone = require("clone");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var log = require("./log");
|
var log = require("./log");
|
||||||
|
var util = require("./util");
|
||||||
|
|
||||||
var userSettings = null;
|
var userSettings = null;
|
||||||
var globalSettings = null;
|
var globalSettings = null;
|
||||||
|
var nodeSettings = null;
|
||||||
|
var disableNodeSettings = null;
|
||||||
var storage = null;
|
var storage = null;
|
||||||
|
|
||||||
var persistentSettings = {
|
var persistentSettings = {
|
||||||
@ -38,6 +41,8 @@ var persistentSettings = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
globalSettings = null;
|
globalSettings = null;
|
||||||
|
nodeSettings = {};
|
||||||
|
disableNodeSettings = {};
|
||||||
},
|
},
|
||||||
load: function(_storage) {
|
load: function(_storage) {
|
||||||
storage = _storage;
|
storage = _storage;
|
||||||
@ -99,6 +104,53 @@ var persistentSettings = {
|
|||||||
userSettings = null;
|
userSettings = null;
|
||||||
globalSettings = null;
|
globalSettings = null;
|
||||||
storage = null;
|
storage = null;
|
||||||
|
},
|
||||||
|
registerNodeSettings: function(type, opts) {
|
||||||
|
try {
|
||||||
|
for (var property in opts) {
|
||||||
|
if (opts.hasOwnProperty(property)) {
|
||||||
|
var normalisedType = util.normaliseNodeTypeName(type);
|
||||||
|
if (!property.startsWith(normalisedType)) {
|
||||||
|
throw new Error("The name of node setting property " + property + " must start with \"" + normalisedType + "\" (case sensitive).");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nodeSettings[type] = opts;
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err.toString());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
exportNodeSettings: function(safeSettings) {
|
||||||
|
safeSettings["nodeSettings"] = {};
|
||||||
|
for (var type in nodeSettings) {
|
||||||
|
if (nodeSettings.hasOwnProperty(type) && !disableNodeSettings[type]) {
|
||||||
|
var nodeTypeSettings = nodeSettings[type];
|
||||||
|
for (var property in nodeTypeSettings) {
|
||||||
|
if (nodeTypeSettings.hasOwnProperty(property)) {
|
||||||
|
var setting = nodeTypeSettings[property];
|
||||||
|
if (setting.exportable) {
|
||||||
|
if (userSettings.hasOwnProperty(property)) {
|
||||||
|
safeSettings["nodeSettings"][property] = userSettings[property];
|
||||||
|
} else {
|
||||||
|
safeSettings["nodeSettings"][property] = setting.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return safeSettings;
|
||||||
|
},
|
||||||
|
enableNodeSettings: function(types) {
|
||||||
|
types.forEach(function(type) {
|
||||||
|
disableNodeSettings[type] = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
disableNodeSettings: function(types) {
|
||||||
|
types.forEach(function(type) {
|
||||||
|
disableNodeSettings[type] = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,6 +328,18 @@ function evaluateNodeProperty(value, type, node, msg) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normaliseNodeTypeName(name) {
|
||||||
|
var result = name.replace(/[^a-zA-Z0-9]/g, " ");
|
||||||
|
result = result.trim();
|
||||||
|
result = result.replace(/ +/g, " ");
|
||||||
|
result = result.replace(/ ./g,
|
||||||
|
function(s) {
|
||||||
|
return s.charAt(1).toUpperCase();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
result = result.charAt(0).toLowerCase() + result.slice(1);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
ensureString: ensureString,
|
ensureString: ensureString,
|
||||||
@ -338,5 +350,6 @@ module.exports = {
|
|||||||
getMessageProperty: getMessageProperty,
|
getMessageProperty: getMessageProperty,
|
||||||
setMessageProperty: setMessageProperty,
|
setMessageProperty: setMessageProperty,
|
||||||
evaluateNodeProperty: evaluateNodeProperty,
|
evaluateNodeProperty: evaluateNodeProperty,
|
||||||
normalisePropertyExpression: normalisePropertyExpression
|
normalisePropertyExpression: normalisePropertyExpression,
|
||||||
|
normaliseNodeTypeName: normaliseNodeTypeName
|
||||||
};
|
};
|
||||||
|
@ -49,7 +49,7 @@ module.exports = {
|
|||||||
|
|
||||||
// To disable the option for using local files for storing keys and certificates in the TLS configuration
|
// To disable the option for using local files for storing keys and certificates in the TLS configuration
|
||||||
// node, set this to true
|
// node, set this to true
|
||||||
//tlsDisableLocalFiles:true,
|
//tlsConfigDisableLocalFiles: true,
|
||||||
|
|
||||||
// Colourise the console output of the debug node
|
// Colourise the console output of the debug node
|
||||||
//debugUseColors: true,
|
//debugUseColors: true,
|
||||||
|
@ -29,7 +29,7 @@ describe("api index", function() {
|
|||||||
describe("disables editor", function() {
|
describe("disables editor", function() {
|
||||||
before(function() {
|
before(function() {
|
||||||
api.init({},{
|
api.init({},{
|
||||||
settings:{httpNodeRoot:true, httpAdminRoot: true,disableEditor:true},
|
settings:{httpNodeRoot:true, httpAdminRoot: true,disableEditor:true, exportNodeSettings: function() {}},
|
||||||
events: {on:function(){},removeListener: function(){}},
|
events: {on:function(){},removeListener: function(){}},
|
||||||
log: {info:function(){},_:function(){}},
|
log: {info:function(){},_:function(){}},
|
||||||
nodes: {paletteEditorEnabled: function(){return true}}
|
nodes: {paletteEditorEnabled: function(){return true}}
|
||||||
|
@ -42,7 +42,10 @@ describe("info api", function() {
|
|||||||
foo: 123,
|
foo: 123,
|
||||||
httpNodeRoot: "testHttpNodeRoot",
|
httpNodeRoot: "testHttpNodeRoot",
|
||||||
version: "testVersion",
|
version: "testVersion",
|
||||||
paletteCategories :["red","blue","green"]
|
paletteCategories :["red","blue","green"],
|
||||||
|
exportNodeSettings: function(obj) {
|
||||||
|
obj.testNodeSetting = "helloWorld";
|
||||||
|
}
|
||||||
},
|
},
|
||||||
nodes: {
|
nodes: {
|
||||||
paletteEditorEnabled: function() { return true; }
|
paletteEditorEnabled: function() { return true; }
|
||||||
@ -59,7 +62,9 @@ describe("info api", function() {
|
|||||||
res.body.should.have.property("version","testVersion");
|
res.body.should.have.property("version","testVersion");
|
||||||
res.body.should.have.property("paletteCategories",["red","blue","green"]);
|
res.body.should.have.property("paletteCategories",["red","blue","green"]);
|
||||||
res.body.should.have.property("editorTheme",{test:456});
|
res.body.should.have.property("editorTheme",{test:456});
|
||||||
|
res.body.should.have.property("testNodeSetting","helloWorld");
|
||||||
res.body.should.not.have.property("foo",123);
|
res.body.should.not.have.property("foo",123);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -68,8 +73,8 @@ describe("info api", function() {
|
|||||||
settings: {
|
settings: {
|
||||||
httpNodeRoot: "testHttpNodeRoot",
|
httpNodeRoot: "testHttpNodeRoot",
|
||||||
version: "testVersion",
|
version: "testVersion",
|
||||||
paletteCategories :["red","blue","green"]
|
paletteCategories :["red","blue","green"],
|
||||||
|
exportNodeSettings: function() {}
|
||||||
},
|
},
|
||||||
nodes: {
|
nodes: {
|
||||||
paletteEditorEnabled: function() { return false; }
|
paletteEditorEnabled: function() { return false; }
|
||||||
|
@ -142,4 +142,87 @@ describe("red/settings", function() {
|
|||||||
settings.should.not.have.property("c");
|
settings.should.not.have.property("c");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('registers node settings and exports them', function() {
|
||||||
|
var userSettings = {};
|
||||||
|
settings.init(userSettings);
|
||||||
|
settings.registerNodeSettings("inject", {injectColor:{value:"red", exportable:true}, injectSize:{value:"100", exportable:true}} );
|
||||||
|
settings.registerNodeSettings("mqtt", {mqttColor:{value:"purple", exportable:false}, mqttSize:{value:"50", exportable:true}} );
|
||||||
|
settings.registerNodeSettings("http request", {httpRequest1:{value:"a1", exportable:true}} );
|
||||||
|
settings.registerNodeSettings(" http--request<> ", {httpRequest2:{value:"a2", exportable:true}} );
|
||||||
|
settings.registerNodeSettings("_http_request_", {httpRequest3:{value:"a3", exportable:true}} );
|
||||||
|
settings.registerNodeSettings("mQtT", {mQtTColor:{value:"purple", exportable:true}} );
|
||||||
|
settings.registerNodeSettings("abc123", {abc123:{value:"def456", exportable:true}} );
|
||||||
|
var safeSettings = {};
|
||||||
|
settings.exportNodeSettings(safeSettings);
|
||||||
|
safeSettings["nodeSettings"].should.have.property("injectColor", "red");
|
||||||
|
safeSettings["nodeSettings"].should.have.property("injectSize", "100");
|
||||||
|
safeSettings["nodeSettings"].should.not.have.property("mqttColor");
|
||||||
|
safeSettings["nodeSettings"].should.have.property("mqttSize", "50");
|
||||||
|
safeSettings["nodeSettings"].should.have.property("httpRequest1", "a1");
|
||||||
|
safeSettings["nodeSettings"].should.have.property("httpRequest2", "a2");
|
||||||
|
safeSettings["nodeSettings"].should.have.property("httpRequest3", "a3");
|
||||||
|
safeSettings["nodeSettings"].should.have.property("mQtTColor", "purple");
|
||||||
|
safeSettings["nodeSettings"].should.have.property("abc123", "def456");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('prohibits registering the property whose name do not start with type name', function() {
|
||||||
|
var userSettings = {};
|
||||||
|
settings.init(userSettings);
|
||||||
|
settings.registerNodeSettings("inject", {color:{value:"red", exportable:true}} );
|
||||||
|
settings.registerNodeSettings("_a_b_1_", {ab1Color:{value:"red", exportable:true}} );
|
||||||
|
settings.registerNodeSettings("AB2", {AB2Color:{value:"red", exportable:true}} );
|
||||||
|
settings.registerNodeSettings("abcDef", {abcColor:{value:"red", exportable:true}} );
|
||||||
|
var safeSettings = {};
|
||||||
|
settings.exportNodeSettings(safeSettings);
|
||||||
|
safeSettings["nodeSettings"].should.not.have.property("color");
|
||||||
|
safeSettings["nodeSettings"].should.not.have.property("ab1Color", "blue");
|
||||||
|
safeSettings["nodeSettings"].should.not.have.property("AB2Color");
|
||||||
|
safeSettings["nodeSettings"].should.not.have.property("abcColor");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('overwrites node settings with user settings', function() {
|
||||||
|
var userSettings = {
|
||||||
|
injectColor: "green",
|
||||||
|
mqttColor: "yellow",
|
||||||
|
abColor: [1,2,3]
|
||||||
|
}
|
||||||
|
settings.init(userSettings);
|
||||||
|
settings.registerNodeSettings("inject", {injectColor:{value:"red", exportable:true}} );
|
||||||
|
settings.registerNodeSettings("ab", {abColor:{value:"red", exportable:false}} );
|
||||||
|
var safeSettings = {};
|
||||||
|
settings.exportNodeSettings(safeSettings);
|
||||||
|
safeSettings["nodeSettings"].should.have.property("injectColor", "green");
|
||||||
|
safeSettings["nodeSettings"].should.not.have.property("mqttColor");
|
||||||
|
safeSettings["nodeSettings"].should.not.have.property("abColor");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('disables/enables node settings', function() {
|
||||||
|
var userSettings = {};
|
||||||
|
settings.init(userSettings);
|
||||||
|
|
||||||
|
var safeSettings = {};
|
||||||
|
settings.registerNodeSettings("inject", {injectColor:{value:"red", exportable:true}} );
|
||||||
|
settings.registerNodeSettings("mqtt", {mqttColor:{value:"purple", exportable:true}} );
|
||||||
|
settings.registerNodeSettings("http request", {httpRequestColor:{value:"yellow", exportable:true}} );
|
||||||
|
settings.exportNodeSettings(safeSettings);
|
||||||
|
safeSettings["nodeSettings"].should.have.property("injectColor", "red");
|
||||||
|
safeSettings["nodeSettings"].should.have.property("mqttColor", "purple");
|
||||||
|
safeSettings["nodeSettings"].should.have.property("httpRequestColor", "yellow");
|
||||||
|
|
||||||
|
var types = ["inject", "mqtt"];
|
||||||
|
settings.disableNodeSettings(types);
|
||||||
|
settings.exportNodeSettings(safeSettings);
|
||||||
|
safeSettings["nodeSettings"].should.not.have.property("injectColor");
|
||||||
|
safeSettings["nodeSettings"].should.not.have.property("mqttColor");
|
||||||
|
safeSettings["nodeSettings"].should.have.property("httpRequestColor", "yellow");
|
||||||
|
|
||||||
|
types = ["inject"];
|
||||||
|
settings.enableNodeSettings(types);
|
||||||
|
settings.exportNodeSettings(safeSettings);
|
||||||
|
safeSettings["nodeSettings"].should.have.property("injectColor", "red");
|
||||||
|
safeSettings["nodeSettings"].should.not.have.property("mqttColor");
|
||||||
|
safeSettings["nodeSettings"].should.have.property("httpRequestColor", "yellow");
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -364,4 +364,21 @@ describe("red/util", function() {
|
|||||||
it("fail <blank>",function() { testInvalid("");})
|
it("fail <blank>",function() { testInvalid("");})
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('normaliseNodeTypeName', function() {
|
||||||
|
function normalise(input, expected) {
|
||||||
|
var result = util.normaliseNodeTypeName(input);
|
||||||
|
result.should.eql(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
it('pass blank',function() { normalise("", "") });
|
||||||
|
it('pass ab1',function() { normalise("ab1", "ab1") });
|
||||||
|
it('pass AB1',function() { normalise("AB1", "aB1") });
|
||||||
|
it('pass a b 1',function() { normalise("a b 1", "aB1") });
|
||||||
|
it('pass a-b-1',function() { normalise("a-b-1", "aB1") });
|
||||||
|
it('pass ab1 ',function() { normalise(" ab1 ", "ab1") });
|
||||||
|
it('pass _a_b_1_',function() { normalise("_a_b_1_", "aB1") });
|
||||||
|
it('pass http request',function() { normalise("http request", "httpRequest") });
|
||||||
|
it('pass HttpRequest',function() { normalise("HttpRequest", "httpRequest") });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user