mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-12 16:06:38 +00:00
Allow configuration of client and org subnets
This commit is contained in:
@@ -19,12 +19,13 @@ import { createAdminRole } from "@server/setup/ensureActions";
|
||||
import config from "@server/lib/config";
|
||||
import { fromError } from "zod-validation-error";
|
||||
import { defaultRoleAllowedActions } from "../role";
|
||||
import { getNextAvailableOrgSubnet } from "@server/lib/ip";
|
||||
import { isValidCIDR } from "@server/lib/validators";
|
||||
|
||||
const createOrgSchema = z
|
||||
.object({
|
||||
orgId: z.string(),
|
||||
name: z.string().min(1).max(255)
|
||||
name: z.string().min(1).max(255),
|
||||
subnet: z.string()
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -68,7 +69,16 @@ export async function createOrg(
|
||||
);
|
||||
}
|
||||
|
||||
const { orgId, name } = parsedBody.data;
|
||||
const { orgId, name, subnet } = parsedBody.data;
|
||||
|
||||
if (subnet && !isValidCIDR(subnet)) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.BAD_REQUEST,
|
||||
"Invalid subnet format. Please provide a valid CIDR notation."
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// make sure the orgId is unique
|
||||
const orgExists = await db
|
||||
@@ -89,8 +99,6 @@ export async function createOrg(
|
||||
let error = "";
|
||||
let org: Org | null = null;
|
||||
|
||||
const subnet = await getNextAvailableOrgSubnet();
|
||||
|
||||
await db.transaction(async (trx) => {
|
||||
const allDomains = await trx
|
||||
.select()
|
||||
|
||||
@@ -5,3 +5,4 @@ export * from "./updateOrg";
|
||||
export * from "./listOrgs";
|
||||
export * from "./checkId";
|
||||
export * from "./getOrgOverview";
|
||||
export* from "./pickOrgDefaults";
|
||||
35
server/routers/org/pickOrgDefaults.ts
Normal file
35
server/routers/org/pickOrgDefaults.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import response from "@server/lib/response";
|
||||
import HttpCode from "@server/types/HttpCode";
|
||||
import createHttpError from "http-errors";
|
||||
import logger from "@server/logger";
|
||||
import { getNextAvailableOrgSubnet } from "@server/lib/ip";
|
||||
|
||||
export type PickOrgDefaultsResponse = {
|
||||
subnet: string;
|
||||
};
|
||||
|
||||
export async function pickOrgDefaults(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
): Promise<any> {
|
||||
try {
|
||||
const subnet = await getNextAvailableOrgSubnet();
|
||||
|
||||
return response<PickOrgDefaultsResponse>(res, {
|
||||
data: {
|
||||
subnet: subnet
|
||||
},
|
||||
success: true,
|
||||
error: false,
|
||||
message: "Organization defaults created successfully",
|
||||
status: HttpCode.OK
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
return next(
|
||||
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user