From 20ac5a98a3c9e796b26fb7e59d33c426e3d9fb81 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 23 Jul 2018 17:33:35 -0400 Subject: [PATCH] password agent csv importer --- src/importers/passwordAgentCsvImporter.ts | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/importers/passwordAgentCsvImporter.ts diff --git a/src/importers/passwordAgentCsvImporter.ts b/src/importers/passwordAgentCsvImporter.ts new file mode 100644 index 0000000000..444585661c --- /dev/null +++ b/src/importers/passwordAgentCsvImporter.ts @@ -0,0 +1,40 @@ +import { BaseImporter } from './baseImporter'; +import { Importer } from './importer'; + +import { ImportResult } from '../models/domain/importResult'; + +export class PasswordAgentCsvImporter extends BaseImporter implements Importer { + parse(data: string): ImportResult { + const result = new ImportResult(); + const results = this.parseCsv(data, false); + if (results == null) { + result.success = false; + return result; + } + + results.forEach((value) => { + if (value.length < 9) { + return; + } + const folder = this.getValueOrDefault(value[8], '(None)'); + const folderName = folder !== '(None)' ? folder.split('\\').join('/') : null; + this.processFolder(result, folderName); + const cipher = this.initLoginCipher(); + cipher.notes = this.getValueOrDefault(value[3]); + cipher.name = this.getValueOrDefault(value[0], '--'); + cipher.login.username = this.getValueOrDefault(value[1]); + cipher.login.password = this.getValueOrDefault(value[2]); + cipher.login.uris = this.makeUriArray(value[4]); + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return result; + } +}