1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

buttercup csv importer

This commit is contained in:
Kyle Spearrin 2019-10-04 10:11:26 -04:00
parent b2a8041173
commit e8130e7934
2 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,51 @@
import { BaseImporter } from './baseImporter';
import { Importer } from './importer';
import { ImportResult } from '../models/domain/importResult';
const OfficialProps = [
'!group_id', '!group_name', 'title', 'username', 'password', 'URL', 'id',
];
export class ButtercupCsvImporter 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;
}
results.forEach((value) => {
this.processFolder(result, this.getValueOrDefault(value['!group_name']));
const cipher = this.initLoginCipher();
cipher.name = this.getValueOrDefault(value.title, '--');
cipher.login.username = this.getValueOrDefault(value.username);
cipher.login.password = this.getValueOrDefault(value.password);
cipher.login.uris = this.makeUriArray(value.URL);
let processingCustomFields = false;
for (const prop in value) {
if (value.hasOwnProperty(prop)) {
if (!processingCustomFields && OfficialProps.indexOf(prop) === -1) {
processingCustomFields = true;
}
if (processingCustomFields) {
this.processKvp(cipher, prop, value[prop]);
}
}
}
this.cleanupCipher(cipher);
result.ciphers.push(cipher);
});
if (this.organization) {
this.moveFoldersToCollections(result);
}
result.success = true;
return result;
}
}

View File

@ -30,6 +30,7 @@ import { BitwardenCsvImporter } from '../importers/bitwardenCsvImporter';
import { BitwardenJsonImporter } from '../importers/bitwardenJsonImporter';
import { BlackBerryCsvImporter } from '../importers/blackBerryCsvImporter';
import { BlurCsvImporter } from '../importers/blurCsvImporter';
import { ButtercupCsvImporter } from '../importers/buttercupCsvImporter';
import { ChromeCsvImporter } from '../importers/chromeCsvImporter';
import { ClipperzHtmlImporter } from '../importers/clipperzHtmlImporter';
import { DashlaneJsonImporter } from '../importers/dashlaneJsonImporter';
@ -123,6 +124,7 @@ export class ImportService implements ImportServiceAbstraction {
{ id: 'securesafecsv', name: 'SecureSafe (csv)' },
{ id: 'logmeoncecsv', name: 'LogMeOnce (csv)' },
{ id: 'blackberrycsv', name: 'BlackBerry Password Keeper (csv)' },
{ id: 'buttercupcsv', name: 'Buttercup (csv)' },
];
constructor(private cipherService: CipherService, private folderService: FolderService,
@ -263,6 +265,8 @@ export class ImportService implements ImportServiceAbstraction {
return new LogMeOnceCsvImporter();
case 'blackberrycsv':
return new BlackBerryCsvImporter();
case 'buttercupcsv':
return new ButtercupCsvImporter();
default:
return null;
}