From 6cf3bf02551f62fb269e4e2405d1f501362ab6d2 Mon Sep 17 00:00:00 2001 From: Owen Date: Fri, 21 Feb 2025 17:22:05 -0500 Subject: [PATCH 1/2] Not optional --- server/routers/client/createClient.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/server/routers/client/createClient.ts b/server/routers/client/createClient.ts index 08d20d37..2ae59117 100644 --- a/server/routers/client/createClient.ts +++ b/server/routers/client/createClient.ts @@ -37,10 +37,9 @@ const createClientSchema = z .object({ name: z.string().min(1).max(255), siteId: z.number().int().positive(), - pubKey: z.string().optional(), - subnet: z.string().optional(), - olmId: z.string().optional(), - secret: z.string().optional(), + subnet: z.string(), + olmId: z.string(), + secret: z.string(), type: z.enum(["olm"]) }) .strict(); @@ -65,7 +64,7 @@ export async function createClient( ); } - const { name, type, siteId, pubKey, subnet, olmId, secret } = + const { name, type, siteId, subnet, olmId, secret } = parsedBody.data; const parsedParams = createClientParamsSchema.safeParse(req.params); @@ -104,12 +103,6 @@ export async function createClient( return next(createHttpError(HttpCode.NOT_FOUND, "Site not found")); } - if (site.type !== "newt") { - return next( - createHttpError(HttpCode.BAD_REQUEST, "Site is not a newt site") - ); - } - await db.transaction(async (trx) => { const adminRole = await trx .select() @@ -132,7 +125,6 @@ export async function createClient( siteId, orgId: site.orgId, name, - pubKey, subnet, type }) From f99efbb1e90110b5dda131a9b4a7a4e082418677 Mon Sep 17 00:00:00 2001 From: Owen Date: Fri, 21 Feb 2025 17:23:22 -0500 Subject: [PATCH 2/2] Update the public key and the endpoint --- server/routers/newt/handleGetConfigMessage.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/routers/newt/handleGetConfigMessage.ts b/server/routers/newt/handleGetConfigMessage.ts index 7226ce24..be460ab0 100644 --- a/server/routers/newt/handleGetConfigMessage.ts +++ b/server/routers/newt/handleGetConfigMessage.ts @@ -78,6 +78,16 @@ export const handleGetConfigMessage: MessageHandler = async (context) => { logger.info(`Updated site ${siteId} with new WG Newt info`); } else { + // update the endpoint and the public key + const [siteRes] = await db + .update(sites) + .set({ + publicKey, + endpoint + }) + .where(eq(sites.siteId, siteId)) + .returning(); + site = siteRes; }