mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 01:03:35 +00:00
[AC-2740] Add device-approval to bw serve (#9512)
* Extract bw serve endpoint configuration to a configurator class * Add device-approval endpoints to bw serve
This commit is contained in:
95
bitwarden_license/bit-cli/src/bit-serve-configurator.ts
Normal file
95
bitwarden_license/bit-cli/src/bit-serve-configurator.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
import * as koaRouter from "@koa/router";
|
||||
|
||||
import { OssServeConfigurator } from "@bitwarden/cli/oss-serve-configurator";
|
||||
|
||||
import {
|
||||
ApproveAllCommand,
|
||||
ApproveCommand,
|
||||
DenyAllCommand,
|
||||
DenyCommand,
|
||||
ListCommand,
|
||||
} from "./admin-console/device-approval";
|
||||
import { ServiceContainer } from "./service-container";
|
||||
|
||||
export class BitServeConfigurator extends OssServeConfigurator {
|
||||
constructor(protected override serviceContainer: ServiceContainer) {
|
||||
super(serviceContainer);
|
||||
}
|
||||
|
||||
override configureRouter(router: koaRouter): void {
|
||||
// Register OSS endpoints
|
||||
super.configureRouter(router);
|
||||
|
||||
// Register bit endpoints
|
||||
this.serveDeviceApprovals(router);
|
||||
}
|
||||
|
||||
private serveDeviceApprovals(router: koaRouter) {
|
||||
router.get("/device-approval/:organizationId", async (ctx, next) => {
|
||||
if (await this.errorIfLocked(ctx.response)) {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await ListCommand.create(this.serviceContainer).run(
|
||||
ctx.params.organizationId,
|
||||
);
|
||||
this.processResponse(ctx.response, response);
|
||||
await next();
|
||||
});
|
||||
|
||||
router.post("/device-approval/:organizationId/approve-all", async (ctx, next) => {
|
||||
if (await this.errorIfLocked(ctx.response)) {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await ApproveAllCommand.create(this.serviceContainer).run(
|
||||
ctx.params.organizationId,
|
||||
);
|
||||
this.processResponse(ctx.response, response);
|
||||
await next();
|
||||
});
|
||||
|
||||
router.post("/device-approval/:organizationId/approve/:requestId", async (ctx, next) => {
|
||||
if (await this.errorIfLocked(ctx.response)) {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await ApproveCommand.create(this.serviceContainer).run(
|
||||
ctx.params.organizationId,
|
||||
ctx.params.requestId,
|
||||
);
|
||||
this.processResponse(ctx.response, response);
|
||||
await next();
|
||||
});
|
||||
|
||||
router.post("/device-approval/:organizationId/deny-all", async (ctx, next) => {
|
||||
if (await this.errorIfLocked(ctx.response)) {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await DenyAllCommand.create(this.serviceContainer).run(
|
||||
ctx.params.organizationId,
|
||||
);
|
||||
this.processResponse(ctx.response, response);
|
||||
await next();
|
||||
});
|
||||
|
||||
router.post("/device-approval/:organizationId/deny/:requestId", async (ctx, next) => {
|
||||
if (await this.errorIfLocked(ctx.response)) {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await DenyCommand.create(this.serviceContainer).run(
|
||||
ctx.params.organizationId,
|
||||
ctx.params.requestId,
|
||||
);
|
||||
this.processResponse(ctx.response, response);
|
||||
await next();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user