mirror of
https://github.com/fosrl/pangolin.git
synced 2026-04-10 03:46:37 +00:00
Add scheme
This commit is contained in:
@@ -231,7 +231,7 @@ export const siteResources = pgTable("siteResources", {
|
|||||||
niceId: varchar("niceId").notNull(),
|
niceId: varchar("niceId").notNull(),
|
||||||
name: varchar("name").notNull(),
|
name: varchar("name").notNull(),
|
||||||
mode: varchar("mode").$type<"host" | "cidr" | "http" | "https">().notNull(), // "host" | "cidr" | "http" | "https"
|
mode: varchar("mode").$type<"host" | "cidr" | "http" | "https">().notNull(), // "host" | "cidr" | "http" | "https"
|
||||||
protocol: varchar("protocol"), // only for port mode
|
scheme: varchar("scheme").$type<"http" | "https">(), // only for when we are doing https or http mode
|
||||||
proxyPort: integer("proxyPort"), // only for port mode
|
proxyPort: integer("proxyPort"), // only for port mode
|
||||||
destinationPort: integer("destinationPort"), // only for port mode
|
destinationPort: integer("destinationPort"), // only for port mode
|
||||||
destination: varchar("destination").notNull(), // ip, cidr, hostname; validate against the mode
|
destination: varchar("destination").notNull(), // ip, cidr, hostname; validate against the mode
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ export const siteResources = sqliteTable("siteResources", {
|
|||||||
niceId: text("niceId").notNull(),
|
niceId: text("niceId").notNull(),
|
||||||
name: text("name").notNull(),
|
name: text("name").notNull(),
|
||||||
mode: text("mode").$type<"host" | "cidr" | "http" | "https">().notNull(), // "host" | "cidr" | "http" | "https"
|
mode: text("mode").$type<"host" | "cidr" | "http" | "https">().notNull(), // "host" | "cidr" | "http" | "https"
|
||||||
protocol: text("protocol"), // only for port mode
|
scheme: text("scheme").$type<"http" | "https">(), // only for when we are doing https or http mode
|
||||||
proxyPort: integer("proxyPort"), // only for port mode
|
proxyPort: integer("proxyPort"), // only for port mode
|
||||||
destinationPort: integer("destinationPort"), // only for port mode
|
destinationPort: integer("destinationPort"), // only for port mode
|
||||||
destination: text("destination").notNull(), // ip, cidr, hostname
|
destination: text("destination").notNull(), // ip, cidr, hostname
|
||||||
|
|||||||
@@ -660,9 +660,14 @@ export function generateSubnetProxyTargetV2(
|
|||||||
destination = `${destination}/32`;
|
destination = `${destination}/32`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!siteResource.alias || !siteResource.aliasAddress) {
|
if (
|
||||||
|
!siteResource.alias ||
|
||||||
|
!siteResource.aliasAddress ||
|
||||||
|
!siteResource.destinationPort ||
|
||||||
|
!siteResource.scheme
|
||||||
|
) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`Site resource ${siteResource.siteResourceId} is in HTTP/HTTPS mode but is missing alias or alias address, skipping alias target generation.`
|
`Site resource ${siteResource.siteResourceId} is in HTTP/HTTPS mode but is missing alias or alias address or destinationPort, skipping alias target generation.`
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -675,9 +680,15 @@ export function generateSubnetProxyTargetV2(
|
|||||||
disableIcmp,
|
disableIcmp,
|
||||||
resourceId: siteResource.siteResourceId,
|
resourceId: siteResource.siteResourceId,
|
||||||
protocol: siteResource.mode, // will be either http or https,
|
protocol: siteResource.mode, // will be either http or https,
|
||||||
httpTargets: [],
|
httpTargets: [
|
||||||
tlsCert: "",
|
{
|
||||||
tlsKey: ""
|
destAddr: siteResource.destination,
|
||||||
|
destPort: siteResource.destinationPort,
|
||||||
|
scheme: siteResource.scheme
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// tlsCert: "",
|
||||||
|
// tlsKey: ""
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const createSiteResourceSchema = z
|
|||||||
name: z.string().min(1).max(255),
|
name: z.string().min(1).max(255),
|
||||||
mode: z.enum(["host", "cidr", "http", "https"]),
|
mode: z.enum(["host", "cidr", "http", "https"]),
|
||||||
siteId: z.int(),
|
siteId: z.int(),
|
||||||
// protocol: z.enum(["tcp", "udp"]).optional(),
|
scheme: z.enum(["http", "https"]).optional(),
|
||||||
// proxyPort: z.int().positive().optional(),
|
// proxyPort: z.int().positive().optional(),
|
||||||
destinationPort: z.int().positive().optional(),
|
destinationPort: z.int().positive().optional(),
|
||||||
destination: z.string().min(1),
|
destination: z.string().min(1),
|
||||||
@@ -167,7 +167,7 @@ export async function createSiteResource(
|
|||||||
name,
|
name,
|
||||||
siteId,
|
siteId,
|
||||||
mode,
|
mode,
|
||||||
// protocol,
|
scheme,
|
||||||
// proxyPort,
|
// proxyPort,
|
||||||
destinationPort,
|
destinationPort,
|
||||||
destination,
|
destination,
|
||||||
@@ -232,30 +232,6 @@ export async function createSiteResource(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// // check if resource with same protocol and proxy port already exists (only for port mode)
|
|
||||||
// if (mode === "port" && protocol && proxyPort) {
|
|
||||||
// const [existingResource] = await db
|
|
||||||
// .select()
|
|
||||||
// .from(siteResources)
|
|
||||||
// .where(
|
|
||||||
// and(
|
|
||||||
// eq(siteResources.siteId, siteId),
|
|
||||||
// eq(siteResources.orgId, orgId),
|
|
||||||
// eq(siteResources.protocol, protocol),
|
|
||||||
// eq(siteResources.proxyPort, proxyPort)
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// .limit(1);
|
|
||||||
// if (existingResource && existingResource.siteResourceId) {
|
|
||||||
// return next(
|
|
||||||
// createHttpError(
|
|
||||||
// HttpCode.CONFLICT,
|
|
||||||
// "A resource with the same protocol and proxy port already exists"
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// make sure the alias is unique within the org if provided
|
// make sure the alias is unique within the org if provided
|
||||||
if (alias) {
|
if (alias) {
|
||||||
const [conflict] = await db
|
const [conflict] = await db
|
||||||
@@ -300,6 +276,7 @@ export async function createSiteResource(
|
|||||||
name,
|
name,
|
||||||
mode,
|
mode,
|
||||||
destination,
|
destination,
|
||||||
|
scheme,
|
||||||
destinationPort,
|
destinationPort,
|
||||||
enabled,
|
enabled,
|
||||||
alias,
|
alias,
|
||||||
|
|||||||
@@ -52,7 +52,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", "https"]).optional(),
|
mode: z.enum(["host", "cidr", "http", "https"]).optional(),
|
||||||
// protocol: z.enum(["tcp", "udp"]).nullish(),
|
scheme: z.enum(["http", "https"]).nullish(),
|
||||||
// proxyPort: z.int().positive().nullish(),
|
// proxyPort: z.int().positive().nullish(),
|
||||||
destinationPort: z.int().positive().nullish(),
|
destinationPort: z.int().positive().nullish(),
|
||||||
destination: z.string().min(1).optional(),
|
destination: z.string().min(1).optional(),
|
||||||
@@ -182,6 +182,7 @@ export async function updateSiteResource(
|
|||||||
siteId, // because it can change
|
siteId, // because it can change
|
||||||
niceId,
|
niceId,
|
||||||
mode,
|
mode,
|
||||||
|
scheme,
|
||||||
destination,
|
destination,
|
||||||
destinationPort,
|
destinationPort,
|
||||||
alias,
|
alias,
|
||||||
@@ -354,6 +355,7 @@ export async function updateSiteResource(
|
|||||||
siteId,
|
siteId,
|
||||||
niceId,
|
niceId,
|
||||||
mode,
|
mode,
|
||||||
|
scheme,
|
||||||
destination,
|
destination,
|
||||||
destinationPort,
|
destinationPort,
|
||||||
enabled,
|
enabled,
|
||||||
@@ -458,6 +460,7 @@ export async function updateSiteResource(
|
|||||||
name: name,
|
name: name,
|
||||||
siteId: siteId,
|
siteId: siteId,
|
||||||
mode: mode,
|
mode: mode,
|
||||||
|
scheme,
|
||||||
destination: destination,
|
destination: destination,
|
||||||
destinationPort: destinationPort,
|
destinationPort: destinationPort,
|
||||||
enabled: enabled,
|
enabled: enabled,
|
||||||
|
|||||||
Reference in New Issue
Block a user