mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
CLI import credentials supports decrypted data
This commit is contained in:
parent
873e566489
commit
7eb849b9f7
|
@ -3,6 +3,11 @@ import {
|
||||||
flags,
|
flags,
|
||||||
} from '@oclif/command';
|
} from '@oclif/command';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Credentials,
|
||||||
|
UserSettings,
|
||||||
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Db,
|
Db,
|
||||||
GenericHelpers,
|
GenericHelpers,
|
||||||
|
@ -64,7 +69,15 @@ 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') {
|
||||||
|
// plain data / decrypted input. Should be encrypted first.
|
||||||
|
Credentials.prototype.setData.call(fileContents[i], fileContents[i].data, encryptionKey);
|
||||||
|
}
|
||||||
await Db.collections.Credentials!.save(fileContents[i]);
|
await Db.collections.Credentials!.save(fileContents[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue