2024-01-31 23:17:04 +01:00
|
|
|
import { program, Command } from "commander";
|
2021-02-03 18:44:33 +01:00
|
|
|
|
[AC-1011] Admin Console / Billing code ownership (#4973)
* refactor: move SCIM component to admin-console, refs EC-1011
* refactor: move scimProviderType to admin-console, refs EC-1011
* refactor: move scim-config.api to admin-console, refs EC-1011
* refactor: create models folder and nest existing api contents, refs EC-1011
* refactor: move scim-config to admin-console models, refs EC-1011
* refactor: move billing.component to billing, refs EC-1011
* refactor: remove nested app folder from new billing structure, refs EC-1011
* refactor: move organizations/billing to billing, refs EC-1011
* refactor: move add-credit and adjust-payment to billing/settings, refs EC-1011
* refactor: billing history/sync to billing, refs EC-1011
* refactor: move org plans, payment/method to billing/settings, refs EC-1011
* fix: update legacy file paths for payment-method and tax-info, refs EC-1011
* fix: update imports for scim component, refs EC-1011
* refactor: move subscription and tax-info into billing, refs EC-1011
* refactor: move user-subscription to billing, refs EC-1011
* refactor: move images/cards to billing and update base path, refs EC-1011
* refactor: move payment-method, plan subscription, and plan to billing, refs EC-1011
* refactor: move transaction-type to billing, refs EC-1011
* refactor: move billing-sync-config to billing, refs EC-1011
* refactor: move billing-sync and bit-pay-invoice request to billing, refs EC-1011
* refactor: move org subscription and tax info update requests to billing, refs EC-1011
* fix: broken paths to billing, refs EC-1011
* refactor: move payment request to billing, refs EC-1011
* fix: update remaining imports for payment-request, refs EC-1011
* refactor: move tax-info-update to billing, refs EC-1011
* refactor: move billing-payment, billing-history, and billing responses to billing, refs EC-1011
* refactor: move organization-subscription-responset to billing, refs EC-1011
* refactor: move payment and plan responses to billing, refs EC-1011
* refactor: move subscription response to billing ,refs EC-1011
* refactor: move tax info and rate responses to billing, refs EC-1011
* fix: update remaining path to base response for tax-rate response, refs EC-1011
* refactor: (browser) move organization-service to admin-console, refs EC-1011
* refactor: (browser) move organizaiton-service to admin-console, refs EC-1011
* refactor: (cli) move share command to admin-console, refs EC-1011
* refactor: move organization-collect request model to admin-console, refs EC-1011
* refactor: (web) move organization, collection/user responses to admin-console, refs EC-1011
* refactor: (cli) move selection-read-only to admin-console, refs EC-1011
* refactor: (desktop) move organization-filter to admin-console, refs EC-1011
* refactor: (web) move organization-switcher to admin-console, refs EC-1011
* refactor: (web) move access-selector to admin-console, refs EC-1011
* refactor: (web) move create folder to admin-console, refs EC-1011
* refactor: (web) move org guards folder to admin-console, refs EC-1011
* refactor: (web) move org layout to admin-console, refs EC-1011
* refactor: move manage collections to admin console, refs EC-1011
* refactor: (web) move collection-dialog to admin-console, refs EC-1011
* refactor: (web) move entity users/events and events component to admin-console, refs EC-1011
* refactor: (web) move groups/group-add-edit to admin-console, refs EC-1011
* refactor: (web) move manage, org-manage module, and user-confirm to admin-console, refs EC-1011
* refactor: (web) move people to admin-console, refs EC-1011
* refactor: (web) move reset-password to admin-console, refs EC-1011
* refactor: (web) move organization-routing and module to admin-console, refs EC-1011
* refactor: move admin-console and billing within app scope, refs EC-1011
* fix: update leftover merge conflicts, refs EC-1011
* refactor: (web) member-dialog to admin-console, refs EC-1011
* refactor: (web) move policies to admin-console, refs EC-1011
* refactor: (web) move reporting to admin-console, refs EC-1011
* refactor: (web) move settings to admin-console, refs EC-1011
* refactor: (web) move sponsorships to admin-console, refs EC-1011
* refactor: (web) move tools to admin-console, refs EC-1011
* refactor: (web) move users to admin-console, refs EC-1011
* refactor: (web) move collections to admin-console, refs EC-1011
* refactor: (web) move create-organization to admin-console, refs EC-1011
* refactor: (web) move licensed components to admin-console, refs EC-1011
* refactor: (web) move bit organization modules to admin-console, refs EC-1011
* fix: update leftover import statements for organizations.module, refs EC-1011
* refactor: (web) move personal vault and max timeout to admin-console, refs EC-1011
* refactor: (web) move providers to admin-console, refs EC-1011
* refactor: (libs) move organization service to admin-console, refs EC-1011
* refactor: (libs) move profile org/provider responses and other misc org responses to admin-console, refs EC-1011
* refactor: (libs) move provider request and selectionion-read-only request to admin-console, refs EC-1011
* fix: update missed import path for provider-user-update request, refs EC-1011
* refactor: (libs) move abstractions to admin-console, refs EC-1011
* refactor: (libs) move org/provider enums to admin-console, refs EC-1011
* fix: update downstream import statements from libs changes, refs EC-1011
* refactor: (libs) move data files to admin-console, refs EC-1011
* refactor: (libs) move domain to admin-console, refs EC-1011
* refactor: (libs) move request objects to admin-console, refs EC-1011
* fix: update downstream import changes from libs, refs EC-1011
* refactor: move leftover provider files to admin-console, refs EC-1011
* refactor: (browser) move group policy environment to admin-console, refs EC-1011
* fix: (browser) update downstream import statements, refs EC-1011
* fix: (desktop) update downstream libs moves, refs EC-1011
* fix: (cli) update downstream import changes from libs, refs EC-1011
* refactor: move org-auth related files to admin-console, refs EC-1011
* refactor: (libs) move request objects to admin-console, refs EC-1011
* refactor: move persmissions to admin-console, refs EC-1011
* refactor: move sponsored families to admin-console and fix libs changes, refs EC-1011
* refactor: move collections to admin-console, refs EC-1011
* refactor: move spec file back to spec scope, refs EC-1011
* fix: update downstream imports due to libs changes, refs EC-1011
* fix: udpate downstream import changes due to libs, refs EC-1011
* fix: update downstream imports due to libs changes, refs EC-1011
* fix: update downstream imports from libs changes, refs EC-1011
* fix: update path malformation in jslib-services.module, refs EC-1011
* fix: lint errors from improper casing, refs AC-1011
* fix: update downstream filename changes, refs AC-1011
* fix: (cli) update downstream filename changes, refs AC-1011
* fix: (desktop) update downstream filename changes, refs AC-1011
* fix: (browser) update downstream filename changes, refs AC-1011
* fix: lint errors, refs AC-1011
* fix: prettier, refs AC-1011
* fix: lint fixes for import order, refs AC-1011
* fix: update import path for provider user type, refs AC-1011
* fix: update new codes import paths for admin console structure, refs AC-1011
* fix: lint/prettier, refs AC-1011
* fix: update layout stories path, refs AC-1011
* fix: update comoponents card icons base variable in styles, refs AC-1011
* fix: update provider service path in permissions guard spec, refs AC-1011
* fix: update provider permission guard path, refs AC-1011
* fix: remove unecessary TODO for shared index export statement, refs AC-1011
* refactor: move browser-organization service and cli organization-user response out of admin-console, refs AC-1011
* refactor: move web/browser/desktop collections component to vault domain, refs AC-1011
* refactor: move organization.module out of admin-console scope, refs AC-1011
* fix: prettier, refs AC-1011
* refactor: move organizations-api-key.request out of admin-console scope, refs AC-1011
2023-03-22 16:03:50 +01:00
|
|
|
import { ConfirmCommand } from "./admin-console/commands/confirm.command";
|
|
|
|
import { ShareCommand } from "./admin-console/commands/share.command";
|
2021-02-03 18:44:33 +01:00
|
|
|
import { Main } from "./bw";
|
|
|
|
import { EditCommand } from "./commands/edit.command";
|
|
|
|
import { GetCommand } from "./commands/get.command";
|
|
|
|
import { ListCommand } from "./commands/list.command";
|
|
|
|
import { RestoreCommand } from "./commands/restore.command";
|
2022-11-18 13:20:19 +01:00
|
|
|
import { Response } from "./models/response";
|
2021-02-03 18:44:33 +01:00
|
|
|
import { Program } from "./program";
|
2023-04-19 11:30:46 +02:00
|
|
|
import { ExportCommand } from "./tools/export.command";
|
2023-03-23 11:43:27 +01:00
|
|
|
import { ImportCommand } from "./tools/import.command";
|
2022-03-03 18:24:41 +01:00
|
|
|
import { CliUtils } from "./utils";
|
2023-01-31 22:08:37 +01:00
|
|
|
import { CreateCommand } from "./vault/create.command";
|
|
|
|
import { DeleteCommand } from "./vault/delete.command";
|
2021-02-03 18:44:33 +01:00
|
|
|
|
|
|
|
const writeLn = CliUtils.writeLn;
|
|
|
|
|
|
|
|
export class VaultProgram extends Program {
|
|
|
|
constructor(protected main: Main) {
|
|
|
|
super(main);
|
|
|
|
}
|
|
|
|
|
2021-04-12 17:13:00 +02:00
|
|
|
async register() {
|
2021-02-03 18:44:33 +01:00
|
|
|
program
|
2021-06-22 02:26:28 +02:00
|
|
|
.addCommand(this.listCommand())
|
|
|
|
.addCommand(this.getCommand())
|
|
|
|
.addCommand(this.createCommand())
|
|
|
|
.addCommand(this.editCommand())
|
|
|
|
.addCommand(this.deleteCommand())
|
|
|
|
.addCommand(this.restoreCommand())
|
|
|
|
.addCommand(this.shareCommand("move", false))
|
|
|
|
.addCommand(this.confirmCommand())
|
|
|
|
.addCommand(this.importCommand())
|
|
|
|
.addCommand(this.exportCommand())
|
|
|
|
.addCommand(this.shareCommand("share", true));
|
|
|
|
}
|
|
|
|
|
|
|
|
private validateObject(requestedObject: string, validObjects: string[]): boolean {
|
|
|
|
let success = true;
|
|
|
|
if (!validObjects.includes(requestedObject)) {
|
|
|
|
success = false;
|
|
|
|
this.processResponse(
|
|
|
|
Response.badRequest(
|
|
|
|
'Unknown object "' +
|
|
|
|
requestedObject +
|
|
|
|
'". Allowed objects are ' +
|
|
|
|
validObjects.join(", ") +
|
2021-12-20 18:04:00 +01:00
|
|
|
".",
|
|
|
|
),
|
2021-06-22 02:26:28 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return success;
|
2021-12-20 18:04:00 +01:00
|
|
|
}
|
2021-06-22 02:26:28 +02:00
|
|
|
|
2024-01-31 23:17:04 +01:00
|
|
|
private listCommand(): Command {
|
2021-06-22 02:26:28 +02:00
|
|
|
const listObjects = [
|
|
|
|
"items",
|
|
|
|
"folders",
|
|
|
|
"collections",
|
|
|
|
"org-collections",
|
|
|
|
"org-members",
|
|
|
|
"organizations",
|
|
|
|
];
|
|
|
|
|
2024-01-31 23:17:04 +01:00
|
|
|
return new Command("list")
|
|
|
|
.argument("<object>", "Valid objects are: " + listObjects.join(", "))
|
|
|
|
.description("List an array of objects from the vault.")
|
2021-02-03 18:44:33 +01:00
|
|
|
.option("--search <search>", "Perform a search on the listed objects.")
|
|
|
|
.option("--url <url>", "Filter items of type login with a url-match search.")
|
|
|
|
.option("--folderid <folderid>", "Filter items by folder id.")
|
|
|
|
.option("--collectionid <collectionid>", "Filter items by collection id.")
|
|
|
|
.option(
|
|
|
|
"--organizationid <organizationid>",
|
|
|
|
"Filter items or collections by organization id.",
|
|
|
|
)
|
|
|
|
.option("--trash", "Filter items that are deleted and in the trash.")
|
|
|
|
.on("--help", () => {
|
2021-06-22 02:26:28 +02:00
|
|
|
writeLn("\n Notes:");
|
2021-02-03 18:44:33 +01:00
|
|
|
writeLn("");
|
|
|
|
writeLn(" Combining search with a filter performs a logical AND operation.");
|
|
|
|
writeLn("");
|
|
|
|
writeLn(" Combining multiple filters performs a logical OR operation.");
|
|
|
|
writeLn("");
|
|
|
|
writeLn(" Examples:");
|
|
|
|
writeLn("");
|
|
|
|
writeLn(" bw list items");
|
|
|
|
writeLn(" bw list items --folderid 60556c31-e649-4b5d-8daf-fc1c391a1bf2");
|
|
|
|
writeLn(
|
|
|
|
" bw list items --search google --folderid 60556c31-e649-4b5d-8daf-fc1c391a1bf2",
|
|
|
|
);
|
|
|
|
writeLn(" bw list items --url https://google.com");
|
|
|
|
writeLn(" bw list items --folderid null");
|
|
|
|
writeLn(" bw list items --organizationid notnull");
|
|
|
|
writeLn(
|
|
|
|
" bw list items --folderid 60556c31-e649-4b5d-8daf-fc1c391a1bf2 --organizationid notnull",
|
|
|
|
);
|
|
|
|
writeLn(" bw list items --trash");
|
|
|
|
writeLn(" bw list folders --search email");
|
|
|
|
writeLn(" bw list org-members --organizationid 60556c31-e649-4b5d-8daf-fc1c391a1bf2");
|
|
|
|
writeLn("", true);
|
|
|
|
})
|
|
|
|
.action(async (object, cmd) => {
|
2021-06-22 02:26:28 +02:00
|
|
|
if (!this.validateObject(object, listObjects)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-03 18:44:33 +01:00
|
|
|
await this.exitIfLocked();
|
|
|
|
const command = new ListCommand(
|
|
|
|
this.main.cipherService,
|
|
|
|
this.main.folderService,
|
|
|
|
this.main.collectionService,
|
2021-12-28 21:38:51 +01:00
|
|
|
this.main.organizationService,
|
2021-02-03 18:44:33 +01:00
|
|
|
this.main.searchService,
|
2022-12-19 19:56:16 +01:00
|
|
|
this.main.organizationUserService,
|
2023-11-09 21:17:25 +01:00
|
|
|
this.main.apiService,
|
|
|
|
this.main.eventCollectionService,
|
2021-02-03 18:44:33 +01:00
|
|
|
);
|
|
|
|
const response = await command.run(object, cmd);
|
2021-06-22 02:26:28 +02:00
|
|
|
|
2021-02-03 18:44:33 +01:00
|
|
|
this.processResponse(response);
|
|
|
|
});
|
2021-06-22 02:26:28 +02:00
|
|
|
}
|
2021-02-03 18:44:33 +01:00
|
|
|
|
2024-01-31 23:17:04 +01:00
|
|
|
private getCommand(): Command {
|
2021-06-22 02:26:28 +02:00
|
|
|
const getObjects = [
|
|
|
|
"item",
|
|
|
|
"username",
|
|
|
|
"password",
|
|
|
|
"uri",
|
|
|
|
"totp",
|
|
|
|
"notes",
|
|
|
|
"exposed",
|
|
|
|
"attachment",
|
|
|
|
"folder",
|
|
|
|
"collection",
|
|
|
|
"org-collection",
|
|
|
|
"organization",
|
|
|
|
"template",
|
|
|
|
"fingerprint",
|
|
|
|
"send",
|
|
|
|
];
|
2024-01-31 23:17:04 +01:00
|
|
|
return new Command("get")
|
|
|
|
.argument("<object>", "Valid objects are: " + getObjects.join(", "))
|
|
|
|
.argument("<id>", "Search term or object's globally unique `id`.")
|
|
|
|
.description("Get an object from the vault.")
|
2021-02-03 18:44:33 +01:00
|
|
|
.option("--itemid <itemid>", "Attachment's item id.")
|
|
|
|
.option("--output <output>", "Output directory or filename for attachment.")
|
|
|
|
.option("--organizationid <organizationid>", "Organization id for an organization object.")
|
|
|
|
.on("--help", () => {
|
2021-06-22 02:26:28 +02:00
|
|
|
writeLn("\n If raw output is specified and no output filename or directory is given for");
|
|
|
|
writeLn(" an attachment query, the attachment content is written to stdout.");
|
2021-02-03 18:44:33 +01:00
|
|
|
writeLn("");
|
|
|
|
writeLn(" Examples:");
|
|
|
|
writeLn("");
|
|
|
|
writeLn(" bw get item 99ee88d2-6046-4ea7-92c2-acac464b1412");
|
|
|
|
writeLn(" bw get password https://google.com");
|
|
|
|
writeLn(" bw get totp google.com");
|
2021-05-12 04:19:47 +02:00
|
|
|
writeLn(" bw get notes google.com");
|
2021-02-03 18:44:33 +01:00
|
|
|
writeLn(" bw get exposed yahoo.com");
|
|
|
|
writeLn(
|
|
|
|
" bw get attachment b857igwl1dzrs2 --itemid 99ee88d2-6046-4ea7-92c2-acac464b1412 " +
|
|
|
|
"--output ./photo.jpg",
|
|
|
|
);
|
|
|
|
writeLn(
|
|
|
|
" bw get attachment photo.jpg --itemid 99ee88d2-6046-4ea7-92c2-acac464b1412 --raw",
|
|
|
|
);
|
|
|
|
writeLn(" bw get folder email");
|
|
|
|
writeLn(" bw get template folder");
|
|
|
|
writeLn("", true);
|
|
|
|
})
|
|
|
|
.action(async (object, id, cmd) => {
|
2021-06-22 02:26:28 +02:00
|
|
|
if (!this.validateObject(object, getObjects)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-03 18:44:33 +01:00
|
|
|
await this.exitIfLocked();
|
|
|
|
const command = new GetCommand(
|
|
|
|
this.main.cipherService,
|
|
|
|
this.main.folderService,
|
|
|
|
this.main.collectionService,
|
|
|
|
this.main.totpService,
|
|
|
|
this.main.auditService,
|
|
|
|
this.main.cryptoService,
|
2021-12-28 21:38:51 +01:00
|
|
|
this.main.stateService,
|
2021-02-03 18:44:33 +01:00
|
|
|
this.main.searchService,
|
|
|
|
this.main.apiService,
|
2023-11-09 21:17:25 +01:00
|
|
|
this.main.organizationService,
|
|
|
|
this.main.eventCollectionService,
|
2021-02-03 18:44:33 +01:00
|
|
|
);
|
|
|
|
const response = await command.run(object, id, cmd);
|
|
|
|
this.processResponse(response);
|
|
|
|
});
|
2021-06-22 02:26:28 +02:00
|
|
|
}
|
2021-02-03 18:44:33 +01:00
|
|
|
|
2021-06-22 02:26:28 +02:00
|
|
|
private createCommand() {
|
|
|
|
const createObjects = ["item", "attachment", "folder", "org-collection"];
|
2024-01-31 23:17:04 +01:00
|
|
|
return new Command("create")
|
|
|
|
.argument("<object>", "Valid objects are: " + createObjects.join(", "))
|
|
|
|
.argument(
|
|
|
|
"[encodedJson]",
|
|
|
|
"Encoded json of the object to create. Can also be piped into stdin.",
|
|
|
|
)
|
|
|
|
.description("Create an object in the vault.")
|
2021-02-03 18:44:33 +01:00
|
|
|
.option("--file <file>", "Path to file for attachment.")
|
|
|
|
.option("--itemid <itemid>", "Attachment's item id.")
|
|
|
|
.option("--organizationid <organizationid>", "Organization id for an organization object.")
|
|
|
|
.on("--help", () => {
|
2021-06-22 02:26:28 +02:00
|
|
|
writeLn("\n Examples:");
|
2021-02-03 18:44:33 +01:00
|
|
|
writeLn("");
|
|
|
|
writeLn(" bw create folder eyJuYW1lIjoiTXkgRm9sZGVyIn0K");
|
|
|
|
writeLn(" echo 'eyJuYW1lIjoiTXkgRm9sZGVyIn0K' | bw create folder");
|
|
|
|
writeLn(
|
|
|
|
" bw create attachment --file ./myfile.csv " +
|
|
|
|
"--itemid 16b15b89-65b3-4639-ad2a-95052a6d8f66",
|
|
|
|
);
|
|
|
|
writeLn("", true);
|
|
|
|
})
|
|
|
|
.action(async (object, encodedJson, cmd) => {
|
2021-06-22 02:26:28 +02:00
|
|
|
if (!this.validateObject(object, createObjects)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-03 18:44:33 +01:00
|
|
|
await this.exitIfLocked();
|
|
|
|
const command = new CreateCommand(
|
|
|
|
this.main.cipherService,
|
|
|
|
this.main.folderService,
|
2021-12-28 21:38:51 +01:00
|
|
|
this.main.stateService,
|
2021-02-03 18:44:33 +01:00
|
|
|
this.main.cryptoService,
|
2022-07-08 15:40:31 +02:00
|
|
|
this.main.apiService,
|
|
|
|
this.main.folderApiService,
|
2021-02-03 18:44:33 +01:00
|
|
|
);
|
|
|
|
const response = await command.run(object, encodedJson, cmd);
|
|
|
|
this.processResponse(response);
|
|
|
|
});
|
2021-06-22 02:26:28 +02:00
|
|
|
}
|
2021-02-03 18:44:33 +01:00
|
|
|
|
2024-01-31 23:17:04 +01:00
|
|
|
private editCommand(): Command {
|
2021-06-22 02:26:28 +02:00
|
|
|
const editObjects = ["item", "item-collections", "folder", "org-collection"];
|
2024-01-31 23:17:04 +01:00
|
|
|
return new Command("edit")
|
|
|
|
.argument("<object>", "Valid objects are: " + editObjects.join(", "))
|
|
|
|
.argument("<id>", "Object's globally unique `id`.")
|
|
|
|
.argument(
|
|
|
|
"[encodedJson]",
|
|
|
|
"Encoded json of the object to create. Can also be piped into stdin.",
|
|
|
|
)
|
|
|
|
.description("Edit an object from the vault.")
|
2021-02-03 18:44:33 +01:00
|
|
|
.option("--organizationid <organizationid>", "Organization id for an organization object.")
|
|
|
|
.on("--help", () => {
|
2021-06-22 02:26:28 +02:00
|
|
|
writeLn("\n Examples:");
|
2021-02-03 18:44:33 +01:00
|
|
|
writeLn("");
|
|
|
|
writeLn(
|
|
|
|
" bw edit folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02 eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg==",
|
|
|
|
);
|
|
|
|
writeLn(
|
|
|
|
" echo 'eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg==' | " +
|
|
|
|
"bw edit folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02",
|
|
|
|
);
|
|
|
|
writeLn(
|
|
|
|
" bw edit item-collections 78307355-fd25-416b-88b8-b33fd0e88c82 " +
|
|
|
|
"WyI5NzQwNTNkMC0zYjMzLTRiOTgtODg2ZS1mZWNmNWM4ZGJhOTYiXQ==",
|
|
|
|
);
|
|
|
|
writeLn("", true);
|
|
|
|
})
|
|
|
|
.action(async (object, id, encodedJson, cmd) => {
|
2021-06-22 02:26:28 +02:00
|
|
|
if (!this.validateObject(object, editObjects)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-03 18:44:33 +01:00
|
|
|
await this.exitIfLocked();
|
|
|
|
const command = new EditCommand(
|
|
|
|
this.main.cipherService,
|
|
|
|
this.main.folderService,
|
|
|
|
this.main.cryptoService,
|
2022-07-08 15:40:31 +02:00
|
|
|
this.main.apiService,
|
|
|
|
this.main.folderApiService,
|
2021-02-03 18:44:33 +01:00
|
|
|
);
|
|
|
|
const response = await command.run(object, id, encodedJson, cmd);
|
|
|
|
this.processResponse(response);
|
|
|
|
});
|
2021-06-22 02:26:28 +02:00
|
|
|
}
|
2021-02-03 18:44:33 +01:00
|
|
|
|
2024-01-31 23:17:04 +01:00
|
|
|
private deleteCommand(): Command {
|
2021-06-22 02:26:28 +02:00
|
|
|
const deleteObjects = ["item", "attachment", "folder", "org-collection"];
|
2024-01-31 23:17:04 +01:00
|
|
|
return new Command("delete")
|
|
|
|
.argument("<object>", "Valid objects are: " + deleteObjects.join(", "))
|
|
|
|
.argument("<id>", "Object's globally unique `id`.")
|
|
|
|
.description("Delete an object from the vault.")
|
2021-02-03 18:44:33 +01:00
|
|
|
.option("--itemid <itemid>", "Attachment's item id.")
|
|
|
|
.option("--organizationid <organizationid>", "Organization id for an organization object.")
|
|
|
|
.option(
|
|
|
|
"-p, --permanent",
|
|
|
|
"Permanently deletes the item instead of soft-deleting it (item only).",
|
|
|
|
)
|
|
|
|
.on("--help", () => {
|
2021-06-22 02:26:28 +02:00
|
|
|
writeLn("\n Examples:");
|
2021-02-03 18:44:33 +01:00
|
|
|
writeLn("");
|
|
|
|
writeLn(" bw delete item 7063feab-4b10-472e-b64c-785e2b870b92");
|
|
|
|
writeLn(" bw delete item 89c21cd2-fab0-4f69-8c6e-ab8a0168f69a --permanent");
|
|
|
|
writeLn(" bw delete folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02");
|
|
|
|
writeLn(
|
|
|
|
" bw delete attachment b857igwl1dzrs2 --itemid 310d5ffd-e9a2-4451-af87-ea054dce0f78",
|
|
|
|
);
|
|
|
|
writeLn("", true);
|
|
|
|
})
|
|
|
|
.action(async (object, id, cmd) => {
|
2021-06-22 02:26:28 +02:00
|
|
|
if (!this.validateObject(object, deleteObjects)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-03 18:44:33 +01:00
|
|
|
await this.exitIfLocked();
|
|
|
|
const command = new DeleteCommand(
|
|
|
|
this.main.cipherService,
|
|
|
|
this.main.folderService,
|
2021-12-28 21:38:51 +01:00
|
|
|
this.main.stateService,
|
2022-07-08 15:40:31 +02:00
|
|
|
this.main.apiService,
|
|
|
|
this.main.folderApiService,
|
2021-02-03 18:44:33 +01:00
|
|
|
);
|
|
|
|
const response = await command.run(object, id, cmd);
|
|
|
|
this.processResponse(response);
|
|
|
|
});
|
2021-06-22 02:26:28 +02:00
|
|
|
}
|
2021-02-03 18:44:33 +01:00
|
|
|
|
2024-01-31 23:17:04 +01:00
|
|
|
private restoreCommand(): Command {
|
2021-06-22 02:26:28 +02:00
|
|
|
const restoreObjects = ["item"];
|
2024-01-31 23:17:04 +01:00
|
|
|
return new Command("restore")
|
|
|
|
.argument("<object>", "Valid objects are: " + restoreObjects.join(", "))
|
|
|
|
.argument("<id>", "Object's globally unique `id`.")
|
|
|
|
.description("Restores an object from the trash.")
|
2021-02-03 18:44:33 +01:00
|
|
|
.on("--help", () => {
|
2021-06-22 02:26:28 +02:00
|
|
|
writeLn("\n Examples:");
|
2021-02-03 18:44:33 +01:00
|
|
|
writeLn("");
|
|
|
|
writeLn(" bw restore item 7063feab-4b10-472e-b64c-785e2b870b92");
|
|
|
|
writeLn("", true);
|
|
|
|
})
|
|
|
|
.action(async (object, id, cmd) => {
|
2021-06-22 02:26:28 +02:00
|
|
|
if (!this.validateObject(object, restoreObjects)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-03 18:44:33 +01:00
|
|
|
await this.exitIfLocked();
|
|
|
|
const command = new RestoreCommand(this.main.cipherService);
|
2022-01-19 16:45:14 +01:00
|
|
|
const response = await command.run(object, id);
|
2021-02-03 18:44:33 +01:00
|
|
|
this.processResponse(response);
|
|
|
|
});
|
2021-06-22 02:26:28 +02:00
|
|
|
}
|
2021-02-03 18:44:33 +01:00
|
|
|
|
2024-01-31 23:17:04 +01:00
|
|
|
private shareCommand(commandName: string, deprecated: boolean): Command {
|
|
|
|
return new Command(commandName)
|
|
|
|
.argument("<id>", "Object's globally unique `id`.")
|
|
|
|
.argument("<organizationId>", "Organization's globally unique `id`.")
|
|
|
|
.argument(
|
|
|
|
"[encodedJson]",
|
|
|
|
"Encoded json of an array of collection ids. Can also be piped into stdin.",
|
|
|
|
)
|
|
|
|
.description((deprecated ? "--DEPRECATED-- " : "") + "Move an item to an organization.")
|
2021-02-03 18:44:33 +01:00
|
|
|
.on("--help", () => {
|
2021-06-22 02:26:28 +02:00
|
|
|
writeLn("\n Examples:");
|
2021-02-03 18:44:33 +01:00
|
|
|
writeLn("");
|
2021-06-22 02:26:28 +02:00
|
|
|
writeLn(
|
|
|
|
" bw " +
|
|
|
|
commandName +
|
|
|
|
" 4af958ce-96a7-45d9-beed-1e70fabaa27a " +
|
|
|
|
"6d82949b-b44d-468a-adae-3f3bacb0ea32 WyI5NzQwNTNkMC0zYjMzLTRiOTgtODg2ZS1mZWNmNWM4ZGJhOTYiXQ==",
|
|
|
|
);
|
2021-02-03 18:44:33 +01:00
|
|
|
writeLn(
|
|
|
|
" echo '[\"974053d0-3b33-4b98-886e-fecf5c8dba96\"]' | bw encode | " +
|
2021-06-22 02:26:28 +02:00
|
|
|
"bw " +
|
|
|
|
commandName +
|
|
|
|
" 4af958ce-96a7-45d9-beed-1e70fabaa27a 6d82949b-b44d-468a-adae-3f3bacb0ea32",
|
|
|
|
);
|
|
|
|
if (deprecated) {
|
|
|
|
writeLn("");
|
|
|
|
writeLn('--DEPRECATED See "bw move" for the current implementation--');
|
|
|
|
}
|
2021-02-03 18:44:33 +01:00
|
|
|
writeLn("", true);
|
|
|
|
})
|
|
|
|
.action(async (id, organizationId, encodedJson, cmd) => {
|
|
|
|
await this.exitIfLocked();
|
|
|
|
const command = new ShareCommand(this.main.cipherService);
|
2022-01-19 16:45:14 +01:00
|
|
|
const response = await command.run(id, organizationId, encodedJson);
|
2021-02-03 18:44:33 +01:00
|
|
|
this.processResponse(response);
|
|
|
|
});
|
2021-06-22 02:26:28 +02:00
|
|
|
}
|
2021-02-03 18:44:33 +01:00
|
|
|
|
2024-01-31 23:17:04 +01:00
|
|
|
private confirmCommand(): Command {
|
2021-06-22 02:26:28 +02:00
|
|
|
const confirmObjects = ["org-member"];
|
2024-01-31 23:17:04 +01:00
|
|
|
return new Command("confirm")
|
|
|
|
.argument("<object>", "Valid objects are: " + confirmObjects.join(", "))
|
|
|
|
.argument("<id>", "Object's globally unique `id`.")
|
|
|
|
.description("Confirm an object to the organization.")
|
2021-02-03 18:44:33 +01:00
|
|
|
.option("--organizationid <organizationid>", "Organization id for an organization object.")
|
|
|
|
.on("--help", () => {
|
2021-06-22 02:26:28 +02:00
|
|
|
writeLn("\n Examples:");
|
2021-02-03 18:44:33 +01:00
|
|
|
writeLn("");
|
|
|
|
writeLn(
|
|
|
|
" bw confirm org-member 7063feab-4b10-472e-b64c-785e2b870b92 " +
|
|
|
|
"--organizationid 310d5ffd-e9a2-4451-af87-ea054dce0f78",
|
|
|
|
);
|
|
|
|
writeLn("", true);
|
|
|
|
})
|
|
|
|
.action(async (object, id, cmd) => {
|
2021-06-22 02:26:28 +02:00
|
|
|
if (!this.validateObject(object, confirmObjects)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-03 18:44:33 +01:00
|
|
|
await this.exitIfLocked();
|
2022-12-19 19:56:16 +01:00
|
|
|
const command = new ConfirmCommand(
|
|
|
|
this.main.apiService,
|
|
|
|
this.main.cryptoService,
|
|
|
|
this.main.organizationUserService,
|
|
|
|
);
|
2021-02-03 18:44:33 +01:00
|
|
|
const response = await command.run(object, id, cmd);
|
|
|
|
this.processResponse(response);
|
|
|
|
});
|
2021-06-22 02:26:28 +02:00
|
|
|
}
|
2021-02-03 18:44:33 +01:00
|
|
|
|
2024-01-31 23:17:04 +01:00
|
|
|
private importCommand(): Command {
|
|
|
|
return new Command("import")
|
|
|
|
.argument("[format]", "The format of [input]")
|
|
|
|
.argument("[input]", "Filepath to data to import")
|
|
|
|
.description("Import vault data from a file.")
|
2021-02-03 18:44:33 +01:00
|
|
|
.option("--formats", "List formats")
|
2021-06-16 15:50:29 +02:00
|
|
|
.option("--organizationid <organizationid>", "ID of the organization to import to.")
|
2021-02-03 18:44:33 +01:00
|
|
|
.on("--help", () => {
|
|
|
|
writeLn("\n Examples:");
|
|
|
|
writeLn("");
|
|
|
|
writeLn(" bw import --formats");
|
|
|
|
writeLn(" bw import bitwardencsv ./from/source.csv");
|
|
|
|
writeLn(" bw import keepass2xml keepass_backup.xml");
|
2021-06-16 15:50:29 +02:00
|
|
|
writeLn(
|
|
|
|
" bw import --organizationid cf14adc3-aca5-4573-890a-f6fa231436d9 keepass2xml keepass_backup.xml",
|
|
|
|
);
|
2021-02-03 18:44:33 +01:00
|
|
|
})
|
|
|
|
.action(async (format, filepath, options) => {
|
|
|
|
await this.exitIfLocked();
|
2023-05-30 23:05:45 +02:00
|
|
|
const command = new ImportCommand(
|
|
|
|
this.main.importService,
|
|
|
|
this.main.organizationService,
|
|
|
|
this.main.syncService,
|
|
|
|
);
|
2021-02-03 18:44:33 +01:00
|
|
|
const response = await command.run(format, filepath, options);
|
|
|
|
this.processResponse(response);
|
|
|
|
});
|
2021-06-22 02:26:28 +02:00
|
|
|
}
|
2021-02-03 18:44:33 +01:00
|
|
|
|
2024-01-31 23:17:04 +01:00
|
|
|
private exportCommand(): Command {
|
|
|
|
return new Command("export")
|
|
|
|
.description("Export vault data to a CSV or JSON file.")
|
2021-02-03 18:44:33 +01:00
|
|
|
.option("--output <output>", "Output directory or filename.")
|
|
|
|
.option("--format <format>", "Export file format.")
|
2022-02-23 22:47:32 +01:00
|
|
|
.option(
|
|
|
|
"--password [password]",
|
|
|
|
"Use password to encrypt instead of your Bitwarden account encryption key. Only applies to the encrypted_json format.",
|
|
|
|
)
|
2021-02-03 18:44:33 +01:00
|
|
|
.option("--organizationid <organizationid>", "Organization id for an organization.")
|
|
|
|
.on("--help", () => {
|
|
|
|
writeLn("\n Notes:");
|
|
|
|
writeLn("");
|
2022-02-23 22:47:32 +01:00
|
|
|
writeLn(
|
|
|
|
" Valid formats are `csv`, `json`, and `encrypted_json`. Default format is `csv`.",
|
|
|
|
);
|
2021-02-03 18:44:33 +01:00
|
|
|
writeLn("");
|
|
|
|
writeLn(
|
|
|
|
" If --raw option is specified and no output filename or directory is given, the",
|
|
|
|
);
|
|
|
|
writeLn(" result is written to stdout.");
|
|
|
|
writeLn("");
|
|
|
|
writeLn(" Examples:");
|
|
|
|
writeLn("");
|
|
|
|
writeLn(" bw export");
|
|
|
|
writeLn(" bw --raw export");
|
|
|
|
writeLn(" bw export myPassword321");
|
|
|
|
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);
|
|
|
|
})
|
2022-02-23 22:47:32 +01:00
|
|
|
.action(async (options) => {
|
2021-02-03 18:44:33 +01:00
|
|
|
await this.exitIfLocked();
|
2023-11-09 21:17:25 +01:00
|
|
|
const command = new ExportCommand(
|
|
|
|
this.main.exportService,
|
|
|
|
this.main.policyService,
|
|
|
|
this.main.eventCollectionService,
|
|
|
|
);
|
2022-02-23 22:47:32 +01:00
|
|
|
const response = await command.run(options);
|
2021-02-03 18:44:33 +01:00
|
|
|
this.processResponse(response);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|