mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +00:00
* 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
72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
import { ImportResult } from "../models/import-result";
|
|
|
|
import { BaseImporter } from "./base-importer";
|
|
import { Importer } from "./importer";
|
|
|
|
export class GnomeJsonImporter extends BaseImporter implements Importer {
|
|
parse(data: string): Promise<ImportResult> {
|
|
const result = new ImportResult();
|
|
const results = JSON.parse(data);
|
|
if (results == null || Object.keys(results).length === 0) {
|
|
result.success = false;
|
|
return Promise.resolve(result);
|
|
}
|
|
|
|
for (const keyRing in results) {
|
|
if (
|
|
!results.hasOwnProperty(keyRing) || // eslint-disable-line
|
|
this.isNullOrWhitespace(keyRing) ||
|
|
results[keyRing].length === 0
|
|
) {
|
|
continue;
|
|
}
|
|
|
|
results[keyRing].forEach((value: any) => {
|
|
if (
|
|
this.isNullOrWhitespace(value.display_name) ||
|
|
value.display_name.indexOf("http") !== 0
|
|
) {
|
|
return;
|
|
}
|
|
|
|
this.processFolder(result, keyRing);
|
|
const cipher = this.initLoginCipher();
|
|
cipher.name = value.display_name.replace("http://", "").replace("https://", "");
|
|
if (cipher.name.length > 30) {
|
|
cipher.name = cipher.name.substring(0, 30);
|
|
}
|
|
cipher.login.password = this.getValueOrDefault(value.secret);
|
|
cipher.login.uris = this.makeUriArray(value.display_name);
|
|
|
|
if (value.attributes != null) {
|
|
cipher.login.username =
|
|
value.attributes != null
|
|
? this.getValueOrDefault(value.attributes.username_value)
|
|
: null;
|
|
for (const attr in value.attributes) {
|
|
if (
|
|
!value.attributes.hasOwnProperty(attr) || // eslint-disable-line
|
|
attr === "username_value" ||
|
|
attr === "xdg:schema"
|
|
) {
|
|
continue;
|
|
}
|
|
this.processKvp(cipher, attr, value.attributes[attr]);
|
|
}
|
|
}
|
|
|
|
this.convertToNoteIfNeeded(cipher);
|
|
this.cleanupCipher(cipher);
|
|
result.ciphers.push(cipher);
|
|
});
|
|
}
|
|
|
|
if (this.organization) {
|
|
this.moveFoldersToCollections(result);
|
|
}
|
|
|
|
result.success = true;
|
|
return Promise.resolve(result);
|
|
}
|
|
}
|