mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-13 05:35:28 +03: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 {
|
||||
await Db.init();
|
||||
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) {
|
||||
const files = await glob((flags.input.endsWith(path.sep) ? flags.input : flags.input + path.sep) + '*.json');
|
||||
for (i = 0; i < files.length; i++) {
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
@ -69,10 +81,6 @@ export class ImportCredentialsCommand extends Command {
|
||||
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++) {
|
||||
if (typeof fileContents[i].data === 'object') {
|
||||
// plain data / decrypted input. Should be encrypted first.
|
||||
|
Loading…
Reference in New Issue
Block a user