Allow configuration of client and org subnets

This commit is contained in:
Owen
2025-04-16 22:00:24 -04:00
parent 569635f3ed
commit db0328fa71
10 changed files with 218 additions and 48 deletions

View File

@@ -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()