mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-01 02:00:35 +02:00
Update site resources to handle new inference
This commit is contained in:
@@ -49,7 +49,7 @@ const createSiteResourceSchema = z
|
|||||||
name: z.string().min(1).max(255),
|
name: z.string().min(1).max(255),
|
||||||
niceId: z.string().optional(),
|
niceId: z.string().optional(),
|
||||||
// protocol: z.enum(["tcp", "udp"]).optional(),
|
// protocol: z.enum(["tcp", "udp"]).optional(),
|
||||||
mode: z.enum(["host", "cidr", "http", "ssh"]),
|
mode: z.enum(["host", "cidr", "http", "ssh", "inference"]),
|
||||||
ssl: z.boolean().optional(), // only used for http mode
|
ssl: z.boolean().optional(), // only used for http mode
|
||||||
scheme: z.enum(["http", "https"]).optional(),
|
scheme: z.enum(["http", "https"]).optional(),
|
||||||
siteIds: z.array(z.int()).optional(),
|
siteIds: z.array(z.int()).optional(),
|
||||||
@@ -171,6 +171,9 @@ const createSiteResourceSchema = z
|
|||||||
)
|
)
|
||||||
.refine(
|
.refine(
|
||||||
(data) => {
|
(data) => {
|
||||||
|
if (data.mode == "inference") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
(data.siteIds !== undefined && data.siteIds.length > 0) ||
|
(data.siteIds !== undefined && data.siteIds.length > 0) ||
|
||||||
data.siteId !== undefined
|
data.siteId !== undefined
|
||||||
@@ -533,21 +536,24 @@ export async function createSiteResource(
|
|||||||
let newSiteResource: SiteResource | undefined;
|
let newSiteResource: SiteResource | undefined;
|
||||||
try {
|
try {
|
||||||
await db.transaction(async (trx) => {
|
await db.transaction(async (trx) => {
|
||||||
const [network] = await trx
|
let network: typeof networks.$inferSelect | undefined;
|
||||||
.insert(networks)
|
if (mode !== "inference") {
|
||||||
.values({
|
[network] = await trx
|
||||||
scope: "resource",
|
.insert(networks)
|
||||||
orgId: orgId
|
.values({
|
||||||
})
|
scope: "resource",
|
||||||
.returning();
|
orgId: orgId
|
||||||
|
})
|
||||||
|
.returning();
|
||||||
|
|
||||||
if (!network) {
|
if (!network) {
|
||||||
return next(
|
return next(
|
||||||
createHttpError(
|
createHttpError(
|
||||||
HttpCode.INTERNAL_SERVER_ERROR,
|
HttpCode.INTERNAL_SERVER_ERROR,
|
||||||
`Failed to create network`
|
`Failed to create network`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let tcpPortRangeStringAdjusted = tcpPortRangeString;
|
let tcpPortRangeStringAdjusted = tcpPortRangeString;
|
||||||
@@ -566,7 +572,7 @@ export async function createSiteResource(
|
|||||||
name,
|
name,
|
||||||
mode,
|
mode,
|
||||||
ssl,
|
ssl,
|
||||||
networkId: network.networkId,
|
networkId: network ? network.networkId : null,
|
||||||
destination: destination, // the ssh can be null
|
destination: destination, // the ssh can be null
|
||||||
scheme,
|
scheme,
|
||||||
destinationPort,
|
destinationPort,
|
||||||
@@ -582,7 +588,8 @@ export async function createSiteResource(
|
|||||||
(mode == "http" || mode == "ssh" ? true : false), // default to true for http resources, otherwise false
|
(mode == "http" || mode == "ssh" ? true : false), // default to true for http resources, otherwise false
|
||||||
domainId,
|
domainId,
|
||||||
subdomain: finalSubdomain,
|
subdomain: finalSubdomain,
|
||||||
fullDomain
|
fullDomain,
|
||||||
|
requiresExitNodeConnection: mode === "inference" // in the future we might want to have different modes that do this
|
||||||
};
|
};
|
||||||
if (isLicensedSshPam) {
|
if (isLicensedSshPam) {
|
||||||
if (authDaemonPort !== undefined)
|
if (authDaemonPort !== undefined)
|
||||||
@@ -600,11 +607,13 @@ export async function createSiteResource(
|
|||||||
|
|
||||||
//////////////////// update the associations ////////////////////
|
//////////////////// update the associations ////////////////////
|
||||||
|
|
||||||
for (const siteId of siteIds) {
|
if (network) {
|
||||||
await trx.insert(siteNetworks).values({
|
for (const siteId of siteIds) {
|
||||||
siteId: siteId,
|
await trx.insert(siteNetworks).values({
|
||||||
networkId: network.networkId
|
siteId: siteId,
|
||||||
});
|
networkId: network.networkId
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const [adminRole] = await trx
|
const [adminRole] = await trx
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ const updateSiteResourceSchema = z
|
|||||||
)
|
)
|
||||||
.optional(),
|
.optional(),
|
||||||
// mode: z.enum(["host", "cidr", "port"]).optional(),
|
// mode: z.enum(["host", "cidr", "port"]).optional(),
|
||||||
mode: z.enum(["host", "cidr", "http", "ssh"]).optional(),
|
mode: z.enum(["host", "cidr", "http", "ssh", "inference"]).optional(),
|
||||||
ssl: z.boolean().optional(),
|
ssl: z.boolean().optional(),
|
||||||
scheme: z.enum(["http", "https"]).nullish(),
|
scheme: z.enum(["http", "https"]).nullish(),
|
||||||
destinationPort: z.int().positive().nullish(),
|
destinationPort: z.int().positive().nullish(),
|
||||||
@@ -173,6 +173,9 @@ const updateSiteResourceSchema = z
|
|||||||
)
|
)
|
||||||
.refine(
|
.refine(
|
||||||
(data) => {
|
(data) => {
|
||||||
|
if (data.mode == "inference") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// if neither is provided, the existing site associations are left unchanged
|
// if neither is provided, the existing site associations are left unchanged
|
||||||
if (data.siteIds === undefined && data.siteId === undefined) {
|
if (data.siteIds === undefined && data.siteId === undefined) {
|
||||||
return true;
|
return true;
|
||||||
@@ -579,13 +582,15 @@ export async function updateSiteResource(
|
|||||||
disableIcmp:
|
disableIcmp:
|
||||||
mode !== undefined
|
mode !== undefined
|
||||||
? disableIcmp ||
|
? disableIcmp ||
|
||||||
(mode == "http" || mode == "ssh"
|
(mode == "http" || mode == "ssh" ? true : false)
|
||||||
? true
|
|
||||||
: false)
|
|
||||||
: disableIcmp,
|
: disableIcmp,
|
||||||
domainId,
|
domainId,
|
||||||
subdomain: finalSubdomain,
|
subdomain: finalSubdomain,
|
||||||
fullDomain,
|
fullDomain,
|
||||||
|
networkId:
|
||||||
|
mode === "inference" ? null : undefined,
|
||||||
|
requiresExitNodeConnection:
|
||||||
|
mode !== undefined ? mode === "inference" : undefined,
|
||||||
...sshPamSet
|
...sshPamSet
|
||||||
})
|
})
|
||||||
.where(and(eq(siteResources.siteResourceId, siteResourceId)))
|
.where(and(eq(siteResources.siteResourceId, siteResourceId)))
|
||||||
@@ -593,7 +598,20 @@ export async function updateSiteResource(
|
|||||||
|
|
||||||
//////////////////// update the associations ////////////////////
|
//////////////////// update the associations ////////////////////
|
||||||
|
|
||||||
if (siteIds !== undefined) {
|
if (mode === "inference") {
|
||||||
|
// inference resources are not attached to any site network
|
||||||
|
if (existingSiteResource.networkId) {
|
||||||
|
await trx
|
||||||
|
.delete(siteNetworks)
|
||||||
|
.where(
|
||||||
|
eq(
|
||||||
|
siteNetworks.networkId,
|
||||||
|
existingSiteResource.networkId
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
updatedSiteIds = [];
|
||||||
|
} else if (siteIds !== undefined) {
|
||||||
// delete the site - site resources associations
|
// delete the site - site resources associations
|
||||||
await trx
|
await trx
|
||||||
.delete(siteNetworks)
|
.delete(siteNetworks)
|
||||||
|
|||||||
Reference in New Issue
Block a user