mirror of
https://github.com/bitwarden/cli
synced 2026-01-13 21:43:14 +00:00
Add importing of 1passwords 1pux files (#440)
* Pull in jslib * Install jszip * Add method in utils to unzip and extract 1pux file * Add importing/extracting of 1pux files to import command * Update jslib * Update package-lock.json
This commit is contained in:
committed by
GitHub
parent
bc4bd664b6
commit
caf6a1173b
@@ -61,7 +61,13 @@ export class ImportCommand {
|
||||
}
|
||||
|
||||
try {
|
||||
const contents = await CliUtils.readFile(filepath);
|
||||
let contents;
|
||||
if (format === "1password1pux") {
|
||||
contents = await CliUtils.extract1PuxContent(filepath);
|
||||
} else {
|
||||
contents = await CliUtils.readFile(filepath);
|
||||
}
|
||||
|
||||
if (contents === null || contents === "") {
|
||||
return Response.badRequest("Import file was empty.");
|
||||
}
|
||||
|
||||
17
src/utils.ts
17
src/utils.ts
@@ -3,6 +3,8 @@ import * as fs from "fs";
|
||||
import * as inquirer from "inquirer";
|
||||
import * as path from "path";
|
||||
|
||||
import * as JSZip from "jszip";
|
||||
|
||||
import { Response } from "jslib-node/cli/models/response";
|
||||
import { MessageResponse } from "jslib-node/cli/models/response/messageResponse";
|
||||
|
||||
@@ -48,6 +50,21 @@ export class CliUtils {
|
||||
});
|
||||
}
|
||||
|
||||
static extract1PuxContent(input: string): Promise<string> {
|
||||
return new JSZip()
|
||||
.loadAsync(input)
|
||||
.then((zip) => {
|
||||
return zip.file("export.data").async("string");
|
||||
})
|
||||
.then(
|
||||
function success(content) {
|
||||
return content;
|
||||
},
|
||||
function error(e) {
|
||||
return "";
|
||||
}
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Save the given data to a file and determine the target file if necessary.
|
||||
* If output is non-empty, it is used as target filename. Otherwise the target filename is
|
||||
|
||||
Reference in New Issue
Block a user