mirror of
https://github.com/bitwarden/browser
synced 2025-12-22 11:13:46 +00:00
[PM-328] Move common/importer to libs/importer (tools-migration) (#5060)
* Create and register new libs/importer Create package.json Create tsconfig Create jest.config Extend shared and root tsconfig and jest.configs Register with eslint * Move importer-related files to libs/importer * Move importer-spec-related files to libs/importer Move import.service.spec * Update package-lock.json * Set CODEOWNERS for new libs/importer * Register libs/importer with cli and fix imports * Register libs/importer with web and fix imports * Move importOption into models Rename importOptions to import-options * Fix linting issues after updating prettier * Only expose necessary files from libs/importer Fix tsconfig files - Removes the trailing /index on imports in web/cli As the spec-files no longer can access the internals via @bitwarden/importer they import by path (../src/importers) * Add barrel files to vendors with more than one importer
This commit is contained in:
committed by
GitHub
parent
7cfabf053c
commit
a5a12a6723
86
libs/importer/src/importers/padlock-csv-importer.ts
Normal file
86
libs/importer/src/importers/padlock-csv-importer.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { CollectionView } from "@bitwarden/common/admin-console/models/view/collection.view";
|
||||
|
||||
import { ImportResult } from "../models/import-result";
|
||||
|
||||
import { BaseImporter } from "./base-importer";
|
||||
import { Importer } from "./importer";
|
||||
|
||||
export class PadlockCsvImporter extends BaseImporter implements Importer {
|
||||
parse(data: string): Promise<ImportResult> {
|
||||
const result = new ImportResult();
|
||||
const results = this.parseCsv(data, false);
|
||||
if (results == null) {
|
||||
result.success = false;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
let headers: string[] = null;
|
||||
results.forEach((value) => {
|
||||
if (headers == null) {
|
||||
headers = value.map((v: string) => v);
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.length < 2 || value.length !== headers.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.isNullOrWhitespace(value[1])) {
|
||||
if (this.organization) {
|
||||
const tags = (value[1] as string).split(",");
|
||||
tags.forEach((tag) => {
|
||||
tag = tag.trim();
|
||||
let addCollection = true;
|
||||
let collectionIndex = result.collections.length;
|
||||
|
||||
for (let i = 0; i < result.collections.length; i++) {
|
||||
if (result.collections[i].name === tag) {
|
||||
addCollection = false;
|
||||
collectionIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (addCollection) {
|
||||
const collection = new CollectionView();
|
||||
collection.name = tag;
|
||||
result.collections.push(collection);
|
||||
}
|
||||
|
||||
result.collectionRelationships.push([result.ciphers.length, collectionIndex]);
|
||||
});
|
||||
} else {
|
||||
const tags = (value[1] as string).split(",");
|
||||
const tag = tags.length > 0 ? tags[0].trim() : null;
|
||||
this.processFolder(result, tag);
|
||||
}
|
||||
}
|
||||
|
||||
const cipher = this.initLoginCipher();
|
||||
cipher.name = this.getValueOrDefault(value[0], "--");
|
||||
|
||||
for (let i = 2; i < value.length; i++) {
|
||||
const header = headers[i].trim().toLowerCase();
|
||||
if (this.isNullOrWhitespace(value[i]) || this.isNullOrWhitespace(header)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this.usernameFieldNames.indexOf(header) > -1) {
|
||||
cipher.login.username = value[i];
|
||||
} else if (this.passwordFieldNames.indexOf(header) > -1) {
|
||||
cipher.login.password = value[i];
|
||||
} else if (this.uriFieldNames.indexOf(header) > -1) {
|
||||
cipher.login.uris = this.makeUriArray(value[i]);
|
||||
} else {
|
||||
this.processKvp(cipher, headers[i], value[i]);
|
||||
}
|
||||
}
|
||||
|
||||
this.cleanupCipher(cipher);
|
||||
result.ciphers.push(cipher);
|
||||
});
|
||||
|
||||
result.success = true;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user