Merge dev into fix/log-analytics-adjustments

This commit is contained in:
Fred KISSIE
2025-12-10 03:19:14 +01:00
parent 9db2feff77
commit d490cab48c
555 changed files with 9375 additions and 9287 deletions

View File

@@ -20,25 +20,25 @@ import { verifyExitNodeOrgAccess } from "#dynamic/lib/exitNodes";
import { build } from "@server/build";
const createSiteParamsSchema = z.strictObject({
orgId: z.string()
});
orgId: z.string()
});
const createSiteSchema = z.strictObject({
name: z.string().min(1).max(255),
exitNodeId: z.int().positive().optional(),
// subdomain: z
// .string()
// .min(1)
// .max(255)
// .transform((val) => val.toLowerCase())
// .optional(),
pubKey: z.string().optional(),
subnet: z.string().optional(),
newtId: z.string().optional(),
secret: z.string().optional(),
address: z.string().optional(),
type: z.enum(["newt", "wireguard", "local"])
});
name: z.string().min(1).max(255),
exitNodeId: z.int().positive().optional(),
// subdomain: z
// .string()
// .min(1)
// .max(255)
// .transform((val) => val.toLowerCase())
// .optional(),
pubKey: z.string().optional(),
subnet: z.string().optional(),
newtId: z.string().optional(),
secret: z.string().optional(),
address: z.string().optional(),
type: z.enum(["newt", "wireguard", "local"])
});
// .refine((data) => {
// if (data.type === "local") {
// return !config.getRawConfig().flags?.disable_local_sites;

View File

@@ -13,8 +13,8 @@ import { sendToClient } from "#dynamic/routers/ws";
import { OpenAPITags, registry } from "@server/openApi";
const deleteSiteSchema = z.strictObject({
siteId: z.string().transform(Number).pipe(z.int().positive())
});
siteId: z.string().transform(Number).pipe(z.int().positive())
});
registry.registerPath({
method: "delete",
@@ -93,8 +93,11 @@ export async function deleteSite(
data: {}
};
// Don't await this to prevent blocking the response
sendToClient(deletedNewtId, payload).catch(error => {
logger.error("Failed to send termination message to newt:", error);
sendToClient(deletedNewtId, payload).catch((error) => {
logger.error(
"Failed to send termination message to newt:",
error
);
});
}

View File

@@ -5,4 +5,4 @@ export * from "./updateSite";
export * from "./listSites";
export * from "./listSiteRoles";
export * from "./pickSiteDefaults";
export * from "./socketIntegration";
export * from "./socketIntegration";

View File

@@ -10,8 +10,8 @@ import logger from "@server/logger";
import { fromError } from "zod-validation-error";
const listSiteRolesSchema = z.strictObject({
siteId: z.string().transform(Number).pipe(z.int().positive())
});
siteId: z.string().transform(Number).pipe(z.int().positive())
});
export async function listSiteRoles(
req: Request,

View File

@@ -69,8 +69,8 @@ async function getLatestNewtVersion(): Promise<string | null> {
}
const listSitesParamsSchema = z.strictObject({
orgId: z.string()
});
orgId: z.string()
});
const listSitesSchema = z.object({
limit: z

View File

@@ -45,8 +45,8 @@ registry.registerPath({
});
const pickSiteDefaultsSchema = z.strictObject({
orgId: z.string()
});
orgId: z.string()
});
export async function pickSiteDefaults(
req: Request,
@@ -74,7 +74,10 @@ export async function pickSiteDefaults(
if (!randomExitNode) {
return next(
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "No available exit node")
createHttpError(
HttpCode.INTERNAL_SERVER_ERROR,
"No available exit node"
)
);
}
@@ -90,7 +93,10 @@ export async function pickSiteDefaults(
// TODO: we need to lock this subnet for some time so someone else does not take it
const subnets = sitesQuery
.map((site) => site.subnet)
.filter((subnet) => subnet && /^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$/.test(subnet))
.filter(
(subnet) =>
subnet && /^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$/.test(subnet)
)
.filter((subnet) => subnet !== null);
// exclude the exit node address by replacing after the / with a site block size
subnets.push(

View File

@@ -10,10 +10,7 @@ import { z } from "zod";
import { fromError } from "zod-validation-error";
import stoi from "@server/lib/stoi";
import { sendToClient } from "#dynamic/routers/ws";
import {
fetchContainers,
dockerSocket
} from "../newt/dockerSocket";
import { fetchContainers, dockerSocket } from "../newt/dockerSocket";
import cache from "@server/lib/cache";
export interface ContainerNetwork {
@@ -47,13 +44,13 @@ export interface Container {
}
const siteIdParamsSchema = z.strictObject({
siteId: z.string().transform(stoi).pipe(z.int().positive())
});
siteId: z.string().transform(stoi).pipe(z.int().positive())
});
const DockerStatusSchema = z.strictObject({
isAvailable: z.boolean(),
socketPath: z.string().optional()
});
isAvailable: z.boolean(),
socketPath: z.string().optional()
});
function validateSiteIdParams(params: any) {
const parsedParams = siteIdParamsSchema.safeParse(params);
@@ -161,9 +158,7 @@ async function triggerFetch(siteId: number) {
async function queryContainers(siteId: number) {
const { newt } = await getSiteAndNewt(siteId);
const result = cache.get(
`${newt.newtId}:dockerContainers`
) as Container[];
const result = cache.get(`${newt.newtId}:dockerContainers`) as Container[];
if (!result) {
throw createHttpError(
HttpCode.TOO_EARLY,

View File

@@ -12,16 +12,15 @@ import { OpenAPITags, registry } from "@server/openApi";
import { isValidCIDR } from "@server/lib/validators";
const updateSiteParamsSchema = z.strictObject({
siteId: z.string().transform(Number).pipe(z.int().positive())
});
siteId: z.string().transform(Number).pipe(z.int().positive())
});
const updateSiteBodySchema = z.strictObject({
const updateSiteBodySchema = z
.strictObject({
name: z.string().min(1).max(255).optional(),
niceId: z.string().min(1).max(255).optional(),
dockerSocketEnabled: z.boolean().optional(),
remoteSubnets: z
.string()
.optional()
remoteSubnets: z.string().optional()
// subdomain: z
// .string()
// .min(1)
@@ -41,8 +40,7 @@ const updateSiteBodySchema = z.strictObject({
registry.registerPath({
method: "post",
path: "/site/{siteId}",
description:
"Update a site.",
description: "Update a site.",
tags: [OpenAPITags.Site],
request: {
params: updateSiteParamsSchema,
@@ -111,7 +109,9 @@ export async function updateSite(
// if remoteSubnets is provided, ensure it's a valid comma-separated list of cidrs
if (updateData.remoteSubnets) {
const subnets = updateData.remoteSubnets.split(",").map((s) => s.trim());
const subnets = updateData.remoteSubnets
.split(",")
.map((s) => s.trim());
for (const subnet of subnets) {
if (!isValidCIDR(subnet)) {
return next(