diff --git a/packages/cli/commands/import/credentials.ts b/packages/cli/commands/import/credentials.ts index ff9421eb46..ed0da4e94b 100644 --- a/packages/cli/commands/import/credentials.ts +++ b/packages/cli/commands/import/credentials.ts @@ -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.