mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Avoid reencyrpting credentials if they haven't changed
This commit is contained in:
parent
d119594cbf
commit
8e7d52e645
@ -137,6 +137,9 @@ var api = module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (encryptionEnabled && !dirty) {
|
||||||
|
encryptedCredentials = credentials;
|
||||||
|
}
|
||||||
return setupEncryptionPromise.then(function() {
|
return setupEncryptionPromise.then(function() {
|
||||||
if (credentials.hasOwnProperty("$")) {
|
if (credentials.hasOwnProperty("$")) {
|
||||||
// These are encrypted credentials
|
// These are encrypted credentials
|
||||||
@ -160,8 +163,10 @@ var api = module.exports = {
|
|||||||
* @return a promise for backwards compatibility TODO: can this be removed?
|
* @return a promise for backwards compatibility TODO: can this be removed?
|
||||||
*/
|
*/
|
||||||
add: function (id, creds) {
|
add: function (id, creds) {
|
||||||
|
if (!credentialCache.hasOwnProperty(id) || JSON.stringify(creds) !== JSON.stringify(credentialCache[id])) {
|
||||||
credentialCache[id] = creds;
|
credentialCache[id] = creds;
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
}
|
||||||
return when.resolve();
|
return when.resolve();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -258,13 +263,16 @@ var api = module.exports = {
|
|||||||
}
|
}
|
||||||
if (0 === newCreds[cred].length || /^\s*$/.test(newCreds[cred])) {
|
if (0 === newCreds[cred].length || /^\s*$/.test(newCreds[cred])) {
|
||||||
delete savedCredentials[cred];
|
delete savedCredentials[cred];
|
||||||
|
dirty = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!savedCredentials.hasOwnProperty(cred) || JSON.stringify(savedCredentials[cred]) !== JSON.stringify(newCreds[cred])) {
|
||||||
savedCredentials[cred] = newCreds[cred];
|
savedCredentials[cred] = newCreds[cred];
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
credentialCache[nodeID] = savedCredentials;
|
credentialCache[nodeID] = savedCredentials;
|
||||||
dirty = true;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -283,7 +291,8 @@ var api = module.exports = {
|
|||||||
|
|
||||||
export: function() {
|
export: function() {
|
||||||
var result = credentialCache;
|
var result = credentialCache;
|
||||||
if (dirty && encryptionEnabled) {
|
if (encryptionEnabled) {
|
||||||
|
if (dirty) {
|
||||||
try {
|
try {
|
||||||
log.debug("red/runtime/nodes/credentials.export : encrypting");
|
log.debug("red/runtime/nodes/credentials.export : encrypting");
|
||||||
var initVector = crypto.randomBytes(16);
|
var initVector = crypto.randomBytes(16);
|
||||||
@ -292,6 +301,9 @@ var api = module.exports = {
|
|||||||
} catch(err) {
|
} catch(err) {
|
||||||
log.warn(log._("nodes.credentials.error-saving",{message:err.toString()}))
|
log.warn(log._("nodes.credentials.error-saving",{message:err.toString()}))
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
result = encryptedCredentials;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dirty = false;
|
dirty = false;
|
||||||
if (removeDefaultKey) {
|
if (removeDefaultKey) {
|
||||||
|
Loading…
Reference in New Issue
Block a user