From 4d702f4de3dc299ac7c3295b61ff1d21cce17592 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 17 Jul 2018 23:47:28 -0400 Subject: [PATCH] roboform csv importer --- src/importers/roboformCsvImporter.ts | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/importers/roboformCsvImporter.ts diff --git a/src/importers/roboformCsvImporter.ts b/src/importers/roboformCsvImporter.ts new file mode 100644 index 0000000000..6d0cc5a2a4 --- /dev/null +++ b/src/importers/roboformCsvImporter.ts @@ -0,0 +1,44 @@ +import { BaseImporter } from './baseImporter'; +import { Importer } from './importer'; + +import { ImportResult } from '../models/domain/importResult'; + +export class RoboFormCsvImporter extends BaseImporter implements Importer { + parse(data: string): ImportResult { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return result; + } + + let i = 1; + results.forEach((value) => { + const folder = !this.isNullOrWhitespace(value.Folder) && value.Folder.startsWith('/') ? + value.Folder.replace('/', '') : value.Folder; + const folderName = !this.isNullOrWhitespace(folder) ? folder.split('/').join(' > ') : null; + this.processFolder(result, folderName); + + const cipher = this.initLoginCipher(); + cipher.notes = this.getValueOrDefault(value.Note); + cipher.name = this.getValueOrDefault(value.Name, '--'); + cipher.login.username = this.getValueOrDefault(value.Login); + cipher.login.password = this.getValueOrDefault(value.Pwd); + cipher.login.uris = this.makeUriArray(value.Url); + this.cleanupCipher(cipher); + + if (i === results.length && cipher.name === '--' && this.isNullOrWhitespace(cipher.login.password)) { + return; + } + result.ciphers.push(cipher); + i++; + }); + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return result; + } +}