mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 04:47:29 -08:00
🐛 Fix issue with importing decrypted separate credentials #1546
This commit is contained in:
parent
7c21e61151
commit
09d9e12db9
|
@ -56,10 +56,22 @@ export class ImportCredentialsCommand extends Command {
|
||||||
try {
|
try {
|
||||||
await Db.init();
|
await Db.init();
|
||||||
let i;
|
let i;
|
||||||
|
|
||||||
|
const encryptionKey = await UserSettings.getEncryptionKey();
|
||||||
|
if (encryptionKey === undefined) {
|
||||||
|
throw new Error('No encryption key got found to encrypt the credentials!');
|
||||||
|
}
|
||||||
|
|
||||||
if (flags.separate) {
|
if (flags.separate) {
|
||||||
const files = await glob((flags.input.endsWith(path.sep) ? flags.input : flags.input + path.sep) + '*.json');
|
const files = await glob((flags.input.endsWith(path.sep) ? flags.input : flags.input + path.sep) + '*.json');
|
||||||
for (i = 0; i < files.length; i++) {
|
for (i = 0; i < files.length; i++) {
|
||||||
const credential = JSON.parse(fs.readFileSync(files[i], { encoding: 'utf8' }));
|
const credential = JSON.parse(fs.readFileSync(files[i], { encoding: 'utf8' }));
|
||||||
|
|
||||||
|
if (typeof credential.data === 'object') {
|
||||||
|
// plain data / decrypted input. Should be encrypted first.
|
||||||
|
Credentials.prototype.setData.call(credential, credential.data, encryptionKey);
|
||||||
|
}
|
||||||
|
|
||||||
await Db.collections.Credentials!.save(credential);
|
await Db.collections.Credentials!.save(credential);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -69,10 +81,6 @@ export class ImportCredentialsCommand extends Command {
|
||||||
throw new Error(`File does not seem to contain credentials.`);
|
throw new Error(`File does not seem to contain credentials.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const encryptionKey = await UserSettings.getEncryptionKey();
|
|
||||||
if (encryptionKey === undefined) {
|
|
||||||
throw new Error('No encryption key got found to encrypt the credentials!');
|
|
||||||
}
|
|
||||||
for (i = 0; i < fileContents.length; i++) {
|
for (i = 0; i < fileContents.length; i++) {
|
||||||
if (typeof fileContents[i].data === 'object') {
|
if (typeof fileContents[i].data === 'object') {
|
||||||
// plain data / decrypted input. Should be encrypted first.
|
// plain data / decrypted input. Should be encrypted first.
|
||||||
|
|
Loading…
Reference in a new issue