mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07:43:35 +00:00
[AC-2631] Add device-approval command scaffolding (#9351)
* Add device-approval scaffolding * Refactor: move helpers to BaseProgram * Update CODEOWNERS
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import { Response } from "@bitwarden/cli/models/response";
|
||||
|
||||
export class ApproveAllCommand {
|
||||
constructor() {}
|
||||
|
||||
async run(organizationId: string): Promise<Response> {
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Response } from "@bitwarden/cli/models/response";
|
||||
|
||||
export class ApproveCommand {
|
||||
constructor() {}
|
||||
|
||||
async run(id: string): Promise<Response> {
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Response } from "@bitwarden/cli/models/response";
|
||||
|
||||
export class DenyAllCommand {
|
||||
constructor() {}
|
||||
|
||||
async run(organizationId: string): Promise<Response> {
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Response } from "@bitwarden/cli/models/response";
|
||||
|
||||
export class DenyCommand {
|
||||
constructor() {}
|
||||
|
||||
async run(id: string): Promise<Response> {
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import { program, Command } from "commander";
|
||||
|
||||
import { BaseProgram } from "@bitwarden/cli/base-program";
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
|
||||
import { ApproveAllCommand } from "./approve-all.command";
|
||||
import { ApproveCommand } from "./approve.command";
|
||||
import { DenyAllCommand } from "./deny-all.command";
|
||||
import { DenyCommand } from "./deny.command";
|
||||
import { ListCommand } from "./list.command";
|
||||
|
||||
export class DeviceApprovalProgram extends BaseProgram {
|
||||
register() {
|
||||
program.addCommand(this.deviceApprovalCommand());
|
||||
}
|
||||
|
||||
private deviceApprovalCommand() {
|
||||
return new Command("device-approval")
|
||||
.description("Manage device approvals")
|
||||
.addCommand(this.listCommand())
|
||||
.addCommand(this.approveCommand())
|
||||
.addCommand(this.approveAllCommand())
|
||||
.addCommand(this.denyCommand())
|
||||
.addCommand(this.denyAllCommand());
|
||||
}
|
||||
|
||||
private listCommand(): Command {
|
||||
return new Command("list")
|
||||
.description("List all pending requests for an organization")
|
||||
.argument("<organizationId>")
|
||||
.action(async (organizationId: string) => {
|
||||
await this.exitIfFeatureFlagDisabled(FeatureFlag.BulkDeviceApproval);
|
||||
await this.exitIfNotAuthed();
|
||||
|
||||
const cmd = new ListCommand();
|
||||
const response = await cmd.run(organizationId);
|
||||
this.processResponse(response);
|
||||
});
|
||||
}
|
||||
|
||||
private approveCommand(): Command {
|
||||
return new Command("approve")
|
||||
.argument("<id>")
|
||||
.description("Approve a pending request")
|
||||
.action(async (id: string) => {
|
||||
await this.exitIfFeatureFlagDisabled(FeatureFlag.BulkDeviceApproval);
|
||||
await this.exitIfLocked();
|
||||
|
||||
const cmd = new ApproveCommand();
|
||||
const response = await cmd.run(id);
|
||||
this.processResponse(response);
|
||||
});
|
||||
}
|
||||
|
||||
private approveAllCommand(): Command {
|
||||
return new Command("approveAll")
|
||||
.description("Approve all pending requests for an organization")
|
||||
.argument("<organizationId>")
|
||||
.action(async (organizationId: string) => {
|
||||
await this.exitIfFeatureFlagDisabled(FeatureFlag.BulkDeviceApproval);
|
||||
await this.exitIfLocked();
|
||||
|
||||
const cmd = new ApproveAllCommand();
|
||||
const response = await cmd.run(organizationId);
|
||||
this.processResponse(response);
|
||||
});
|
||||
}
|
||||
|
||||
private denyCommand(): Command {
|
||||
return new Command("deny")
|
||||
.argument("<id>")
|
||||
.description("Deny a pending request")
|
||||
.action(async (id: string) => {
|
||||
await this.exitIfFeatureFlagDisabled(FeatureFlag.BulkDeviceApproval);
|
||||
await this.exitIfLocked();
|
||||
|
||||
const cmd = new DenyCommand();
|
||||
const response = await cmd.run(id);
|
||||
this.processResponse(response);
|
||||
});
|
||||
}
|
||||
|
||||
private denyAllCommand(): Command {
|
||||
return new Command("denyAll")
|
||||
.description("Deny all pending requests for an organization")
|
||||
.argument("<organizationId>")
|
||||
.action(async (organizationId: string) => {
|
||||
await this.exitIfFeatureFlagDisabled(FeatureFlag.BulkDeviceApproval);
|
||||
await this.exitIfLocked();
|
||||
|
||||
const cmd = new DenyAllCommand();
|
||||
const response = await cmd.run(organizationId);
|
||||
this.processResponse(response);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { DeviceApprovalProgram } from "./device-approval.program";
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Response } from "@bitwarden/cli/models/response";
|
||||
|
||||
export class ListCommand {
|
||||
constructor() {}
|
||||
|
||||
async run(organizationId: string): Promise<Response> {
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DeviceApprovalProgram } from "./admin-console/device-approval";
|
||||
import { ServiceContainer } from "./service-container";
|
||||
|
||||
/**
|
||||
@@ -7,4 +8,6 @@ import { ServiceContainer } from "./service-container";
|
||||
* myProgram.register();
|
||||
* @param serviceContainer A class that instantiates services and makes them available for dependency injection
|
||||
*/
|
||||
export async function registerBitPrograms(serviceContainer: ServiceContainer) {}
|
||||
export async function registerBitPrograms(serviceContainer: ServiceContainer) {
|
||||
new DeviceApprovalProgram(serviceContainer).register();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user