1
0
mirror of https://github.com/bitwarden/browser synced 2025-01-19 07:50:08 +01:00

allow org exports

This commit is contained in:
Kyle Spearrin 2019-10-07 11:01:30 -04:00
parent 99c4291ee7
commit 93c2ce2582
2 changed files with 17 additions and 2 deletions

View File

@ -9,6 +9,8 @@ import { MessageResponse } from 'jslib/cli/models/response/messageResponse';
import { CliUtils } from '../utils';
import { Utils } from 'jslib/misc/utils';
export class ExportCommand {
constructor(private cryptoService: CryptoService, private exportService: ExportService) { }
@ -29,7 +31,17 @@ export class ExportCommand {
const storedKeyHash = await this.cryptoService.getKeyHash();
if (storedKeyHash != null && keyHash != null && storedKeyHash === keyHash) {
const format = cmd.format !== 'json' ? 'csv' : 'json';
const csv = await this.exportService.getExport(format);
if (cmd.organizationid != null && !Utils.isGuid(cmd.organizationid)) {
return Response.error('`' + cmd.organizationid + '` is not a GUID.');
}
let csv: string = null;
try {
csv = cmd.organizationid != null ?
await this.exportService.getOrganizationExport(cmd.organizationid, format) :
await this.exportService.getExport(format);
} catch (e) {
return Response.error(e);
}
return await this.saveFile(csv, cmd, format);
} else {
return Response.error('Invalid master password.');
@ -38,7 +50,8 @@ export class ExportCommand {
async saveFile(csv: string, cmd: program.Command, format: string): Promise<Response> {
try {
const filePath = await CliUtils.saveFile(csv, cmd.output, this.exportService.getFileName(null, format));
const filePath = await CliUtils.saveFile(csv, cmd.output,
this.exportService.getFileName(cmd.organizationid != null ? 'org' : null, format));
const res = new MessageResponse('Saved ' + filePath, null);
res.raw = filePath;
return Response.success(res);

View File

@ -497,6 +497,7 @@ export class Program extends BaseProgram {
.description('Export vault data to a CSV or JSON file.')
.option('--output <output>', 'Output directory or filename.')
.option('--format <format>', 'Export file format.')
.option('--organizationid <organizationid>', 'Organization id for an organization.')
.on('--help', () => {
writeLn('\n Notes:');
writeLn('');
@ -509,6 +510,7 @@ export class Program extends BaseProgram {
writeLn(' bw export myPassword321 --format json');
writeLn(' bw export --output ./exp/bw.csv');
writeLn(' bw export myPassword321 --output bw.json --format json');
writeLn(' bw export myPassword321 --organizationid 7063feab-4b10-472e-b64c-785e2b870b92');
writeLn('', true);
})
.action(async (password, cmd) => {