Properly generate all wireguard options

This commit is contained in:
Owen Schwartz 2024-10-26 16:04:01 -04:00
parent 261b3c7e31
commit d78312fad8
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD
12 changed files with 303 additions and 65 deletions

View file

@ -9,7 +9,7 @@ import fetch from 'node-fetch';
import { ActionsEnum, checkUserActionPermission } from '@server/auth/actions';
import logger from '@server/logger';
import { eq, and } from 'drizzle-orm';
import { getUniqueName } from '@server/db/names';
import { getUniqueSiteName } from '@server/db/names';
const API_BASE_URL = "http://localhost:3000";
@ -20,9 +20,10 @@ const createSiteParamsSchema = z.object({
// Define Zod schema for request body validation
const createSiteSchema = z.object({
name: z.string().min(1).max(255),
exitNodeId: z.number().int().positive(),
subdomain: z.string().min(1).max(255).optional(),
pubKey: z.string().optional(),
subnet: z.string().optional(),
pubKey: z.string(),
subnet: z.string(),
});
export type CreateSiteResponse = {
@ -48,7 +49,7 @@ export async function createSite(req: Request, res: Response, next: NextFunction
);
}
const { name, subdomain, pubKey, subnet } = parsedBody.data;
const { name, subdomain, exitNodeId, pubKey, subnet } = parsedBody.data;
// Validate request params
const parsedParams = createSiteParamsSchema.safeParse(req.params);
@ -73,13 +74,12 @@ export async function createSite(req: Request, res: Response, next: NextFunction
return next(createHttpError(HttpCode.FORBIDDEN, 'User does not have a role'));
}
const niceId = await getUniqueName(orgId);
// TODO: pick a subnet
const niceId = await getUniqueSiteName(orgId);
// Create new site in the database
const [newSite] = await db.insert(sites).values({
orgId,
exitNodeId,
name,
niceId,
pubKey,