mirror of
https://github.com/fosrl/pangolin.git
synced 2026-04-04 08:56:37 +00:00
Generate address
This commit is contained in:
@@ -27,7 +27,7 @@ import { build } from "@server/build";
|
|||||||
import { usageService } from "@server/lib/billing/usageService";
|
import { usageService } from "@server/lib/billing/usageService";
|
||||||
import { FeatureId } from "@server/lib/billing";
|
import { FeatureId } from "@server/lib/billing";
|
||||||
import { INSPECT_MAX_BYTES } from "buffer";
|
import { INSPECT_MAX_BYTES } from "buffer";
|
||||||
import { v } from "@faker-js/faker/dist/airline-Dz1uGqgJ";
|
import { getNextAvailableClientSubnet } from "@server/lib/ip";
|
||||||
|
|
||||||
const bodySchema = z.object({
|
const bodySchema = z.object({
|
||||||
provisioningKey: z.string().nonempty(),
|
provisioningKey: z.string().nonempty(),
|
||||||
@@ -152,6 +152,11 @@ export async function registerNewt(
|
|||||||
createHttpError(HttpCode.NOT_FOUND, "Organization not found")
|
createHttpError(HttpCode.NOT_FOUND, "Organization not found")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (!org.subnet) {
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "Organization subnet not found")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// SaaS billing check
|
// SaaS billing check
|
||||||
if (build == "saas") {
|
if (build == "saas") {
|
||||||
@@ -190,6 +195,20 @@ export async function registerNewt(
|
|||||||
let newSiteId: number | undefined;
|
let newSiteId: number | undefined;
|
||||||
|
|
||||||
await db.transaction(async (trx) => {
|
await db.transaction(async (trx) => {
|
||||||
|
|
||||||
|
const newClientAddress = await getNextAvailableClientSubnet(orgId);
|
||||||
|
if (!newClientAddress) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"No available subnet found"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let clientAddress = newClientAddress.split("/")[0];
|
||||||
|
clientAddress = `${clientAddress}/${org.subnet!.split("/")[1]}`; // we want the block size of the whole org
|
||||||
|
|
||||||
// Create the site (type "newt", name = niceId)
|
// Create the site (type "newt", name = niceId)
|
||||||
const [newSite] = await trx
|
const [newSite] = await trx
|
||||||
.insert(sites)
|
.insert(sites)
|
||||||
@@ -197,6 +216,7 @@ export async function registerNewt(
|
|||||||
orgId,
|
orgId,
|
||||||
name: name || niceId,
|
name: name || niceId,
|
||||||
niceId,
|
niceId,
|
||||||
|
address: clientAddress,
|
||||||
type: "newt",
|
type: "newt",
|
||||||
dockerSocketEnabled: true,
|
dockerSocketEnabled: true,
|
||||||
status: keyRecord.approveNewSites ? "approved" : "pending",
|
status: keyRecord.approveNewSites ? "approved" : "pending",
|
||||||
|
|||||||
Reference in New Issue
Block a user