mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Fully remove when.js dependency
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var when = require("when");
|
||||
var crypto = require('crypto');
|
||||
var runtime;
|
||||
var settings;
|
||||
@@ -60,7 +59,7 @@ var api = module.exports = {
|
||||
/**
|
||||
* Sets the credentials from storage.
|
||||
*/
|
||||
load: function (credentials) {
|
||||
load: async function (credentials) {
|
||||
dirty = false;
|
||||
var credentialsEncrypted = credentials.hasOwnProperty("$") && Object.keys(credentials).length === 1;
|
||||
|
||||
@@ -77,7 +76,7 @@ var api = module.exports = {
|
||||
// Case 4: credentialSecret set
|
||||
// - use it
|
||||
|
||||
var setupEncryptionPromise = when.resolve();
|
||||
var setupEncryptionPromise = Promise.resolve();
|
||||
|
||||
var projectKey = false;
|
||||
var activeProject;
|
||||
@@ -134,7 +133,7 @@ var api = module.exports = {
|
||||
log.warn(log._("nodes.credentials.error",{message:err.toString()}))
|
||||
var error = new Error("Failed to decrypt credentials");
|
||||
error.code = "credentials_load_failed";
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
dirty = true;
|
||||
@@ -163,7 +162,7 @@ var api = module.exports = {
|
||||
log.warn(log._("nodes.credentials.error",{message:err.toString()}))
|
||||
var error = new Error("Failed to decrypt credentials");
|
||||
error.code = "credentials_load_failed";
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
dirty = true;
|
||||
@@ -217,9 +216,9 @@ var api = module.exports = {
|
||||
// This is a project with a bad key. Mark it as invalid
|
||||
// TODO: this delves too deep into Project structure
|
||||
activeProject.credentialSecretInvalid = true;
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
// These are encrypted credentials
|
||||
try {
|
||||
@@ -235,9 +234,9 @@ var api = module.exports = {
|
||||
// This is a project with a bad key. Mark it as invalid
|
||||
// TODO: this delves too deep into Project structure
|
||||
activeProject.credentialSecretInvalid = true;
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
return when.reject(error);
|
||||
throw error;
|
||||
}
|
||||
} else {
|
||||
credentialCache = credentials;
|
||||
@@ -257,12 +256,11 @@ var api = module.exports = {
|
||||
* @param creds an object of credential key/value pairs
|
||||
* @return a promise for backwards compatibility TODO: can this be removed?
|
||||
*/
|
||||
add: function (id, creds) {
|
||||
add: async function (id, creds) {
|
||||
if (!credentialCache.hasOwnProperty(id) || JSON.stringify(creds) !== JSON.stringify(credentialCache[id])) {
|
||||
credentialCache[id] = creds;
|
||||
dirty = true;
|
||||
}
|
||||
return when.resolve();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -293,7 +291,7 @@ var api = module.exports = {
|
||||
* @param config a flow config
|
||||
* @return a promise for the saving of credentials to storage
|
||||
*/
|
||||
clean: function (config) {
|
||||
clean: async function (config) {
|
||||
var existingIds = {};
|
||||
config.forEach(function(n) {
|
||||
existingIds[n.id] = true;
|
||||
@@ -313,7 +311,6 @@ var api = module.exports = {
|
||||
if (deletedCredentials) {
|
||||
dirty = true;
|
||||
}
|
||||
return when.resolve();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -432,7 +429,7 @@ var api = module.exports = {
|
||||
getKeyType: function() {
|
||||
return encryptionKeyType;
|
||||
},
|
||||
export: function() {
|
||||
export: async function() {
|
||||
var result = credentialCache;
|
||||
|
||||
if (encryptionEnabled) {
|
||||
@@ -455,7 +452,7 @@ var api = module.exports = {
|
||||
return result;
|
||||
})
|
||||
} else {
|
||||
return when.resolve(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var when = require("when");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var clone = require("clone");
|
||||
|
Reference in New Issue
Block a user