mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-17 21:01:53 +00:00
Add target mode and auth token
This commit is contained in:
@@ -48,6 +48,9 @@ import { fireHealthCheckUnknownAlert } from "@server/lib/alerts";
|
|||||||
import { tierMatrix } from "../billing/tierMatrix";
|
import { tierMatrix } from "../billing/tierMatrix";
|
||||||
import { defaultRoleAllowedActions } from "@server/routers/role/createRole";
|
import { defaultRoleAllowedActions } from "@server/routers/role/createRole";
|
||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
|
import { encrypt } from "@server/lib/crypto";
|
||||||
|
import { generateId } from "@server/auth/sessions/app";
|
||||||
|
import serverConfig from "@server/lib/config";
|
||||||
|
|
||||||
export type ProxyResourcesResults = {
|
export type ProxyResourcesResults = {
|
||||||
proxyResource: Resource;
|
proxyResource: Resource;
|
||||||
@@ -80,7 +83,7 @@ export async function updateProxyResources(
|
|||||||
if (targetSiteId) {
|
if (targetSiteId) {
|
||||||
// Look up site by niceId
|
// Look up site by niceId
|
||||||
[site] = await trx
|
[site] = await trx
|
||||||
.select({ siteId: sites.siteId })
|
.select({ siteId: sites.siteId, type: sites.type })
|
||||||
.from(sites)
|
.from(sites)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
@@ -92,7 +95,7 @@ export async function updateProxyResources(
|
|||||||
} else if (siteId) {
|
} else if (siteId) {
|
||||||
// Use the provided siteId directly, but verify it belongs to the org
|
// Use the provided siteId directly, but verify it belongs to the org
|
||||||
[site] = await trx
|
[site] = await trx
|
||||||
.select({ siteId: sites.siteId })
|
.select({ siteId: sites.siteId, type: sites.type })
|
||||||
.from(sites)
|
.from(sites)
|
||||||
.where(
|
.where(
|
||||||
and(eq(sites.siteId, siteId), eq(sites.orgId, orgId))
|
and(eq(sites.siteId, siteId), eq(sites.orgId, orgId))
|
||||||
@@ -119,6 +122,15 @@ export async function updateProxyResources(
|
|||||||
internalPortToCreate = targetData["internal-port"];
|
internalPortToCreate = targetData["internal-port"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let authToken: string | undefined;
|
||||||
|
if (site.type !== "local") {
|
||||||
|
const plainToken = generateId(48);
|
||||||
|
authToken = encrypt(
|
||||||
|
plainToken,
|
||||||
|
serverConfig.getRawConfig().server.secret!
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Create target
|
// Create target
|
||||||
const [newTarget] = await trx
|
const [newTarget] = await trx
|
||||||
.insert(targets)
|
.insert(targets)
|
||||||
@@ -126,10 +138,12 @@ export async function updateProxyResources(
|
|||||||
resourceId: resourceId,
|
resourceId: resourceId,
|
||||||
siteId: site.siteId,
|
siteId: site.siteId,
|
||||||
ip: targetData.hostname,
|
ip: targetData.hostname,
|
||||||
|
mode: resourceData.mode as Target["mode"],
|
||||||
method: targetData.method,
|
method: targetData.method,
|
||||||
port: targetData.port,
|
port: targetData.port,
|
||||||
enabled: targetData.enabled,
|
enabled: targetData.enabled,
|
||||||
internalPort: internalPortToCreate,
|
internalPort: internalPortToCreate,
|
||||||
|
authToken: authToken,
|
||||||
path: targetData.path,
|
path: targetData.path,
|
||||||
pathMatchType: targetData["path-match"],
|
pathMatchType: targetData["path-match"],
|
||||||
rewritePath:
|
rewritePath:
|
||||||
@@ -707,7 +721,8 @@ export async function updateProxyResources(
|
|||||||
? "/"
|
? "/"
|
||||||
: undefined),
|
: undefined),
|
||||||
rewritePathType: targetData["rewrite-match"],
|
rewritePathType: targetData["rewrite-match"],
|
||||||
priority: targetData.priority
|
priority: targetData.priority,
|
||||||
|
mode: resourceData.mode
|
||||||
})
|
})
|
||||||
.where(eq(targets.targetId, existingTarget.targetId))
|
.where(eq(targets.targetId, existingTarget.targetId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
Reference in New Issue
Block a user