feat: add gateway registration and org-proxy initialization

This commit is contained in:
Sheen Capadngan
2025-08-27 04:36:17 +08:00
parent cc34b92d56
commit ae62c59382
19 changed files with 944 additions and 20 deletions
@@ -67,6 +67,43 @@ export async function up(knex: Knex): Promise<void> {
await createOnUpdateTrigger(knex, TableName.OrgProxyConfig);
}
if (!(await knex.schema.hasTable(TableName.OrgGatewayConfigV2))) {
await knex.schema.createTable(TableName.OrgGatewayConfigV2, (t) => {
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
t.uuid("orgId").notNullable().unique();
t.foreign("orgId").references("id").inTable(TableName.Organization).onDelete("CASCADE");
t.timestamps(true, true, true);
t.binary("encryptedRootGatewayCaPrivateKey").notNullable();
t.binary("encryptedRootGatewayCaCertificate").notNullable();
t.binary("encryptedGatewayServerCaPrivateKey").notNullable();
t.binary("encryptedGatewayServerCaCertificate").notNullable();
t.binary("encryptedGatewayServerCaCertificateChain").notNullable();
t.binary("encryptedGatewayClientCaPrivateKey").notNullable();
t.binary("encryptedGatewayClientCaCertificate").notNullable();
t.binary("encryptedGatewayClientCaCertificateChain").notNullable();
});
await createOnUpdateTrigger(knex, TableName.OrgGatewayConfigV2);
}
if (!(await knex.schema.hasTable(TableName.Proxy))) {
await knex.schema.createTable(TableName.Proxy, (t) => {
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
t.timestamps(true, true, true);
t.uuid("orgId");
t.foreign("orgId").references("id").inTable(TableName.Organization).onDelete("CASCADE");
t.uuid("identityId");
t.foreign("identityId").references("id").inTable(TableName.Identity).onDelete("CASCADE");
t.string("name").notNullable().unique();
t.string("ip").notNullable();
});
await createOnUpdateTrigger(knex, TableName.Proxy);
}
}
export async function down(knex: Knex): Promise<void> {
@@ -75,4 +112,10 @@ export async function down(knex: Knex): Promise<void> {
await dropOnUpdateTrigger(knex, TableName.InstanceProxyConfig);
await knex.schema.dropTableIfExists(TableName.InstanceProxyConfig);
await dropOnUpdateTrigger(knex, TableName.OrgGatewayConfigV2);
await knex.schema.dropTableIfExists(TableName.OrgGatewayConfigV2);
await dropOnUpdateTrigger(knex, TableName.Proxy);
await knex.schema.dropTableIfExists(TableName.Proxy);
}
+2
View File
@@ -76,6 +76,7 @@ export * from "./models";
export * from "./oidc-configs";
export * from "./org-bots";
export * from "./org-gateway-config";
export * from "./org-gateway-config-v2";
export * from "./org-memberships";
export * from "./org-proxy-config";
export * from "./org-roles";
@@ -164,3 +165,4 @@ export * from "./user-group-membership";
export * from "./users";
export * from "./webhooks";
export * from "./workflow-integrations";
export * from "./proxies";
+3 -1
View File
@@ -182,7 +182,9 @@ export enum TableName {
// gateway v2
InstanceProxyConfig = "instance_proxy_config",
OrgProxyConfig = "org_proxy_config"
OrgProxyConfig = "org_proxy_config",
OrgGatewayConfigV2 = "org_gateway_config_v2",
Proxy = "proxies"
}
export type TImmutableDBKeys = "id" | "createdAt" | "updatedAt" | "commitId";
@@ -0,0 +1,29 @@
// Code generated by automation script, DO NOT EDIT.
// Automated by pulling database and generating zod schema
// To update. Just run npm run generate:schema
// Written by akhilmhdh.
import { z } from "zod";
import { zodBuffer } from "@app/lib/zod";
import { TImmutableDBKeys } from "./models";
export const OrgGatewayConfigV2Schema = z.object({
id: z.string().uuid(),
orgId: z.string().uuid(),
createdAt: z.date(),
updatedAt: z.date(),
encryptedRootGatewayCaPrivateKey: zodBuffer,
encryptedRootGatewayCaCertificate: zodBuffer,
encryptedGatewayServerCaPrivateKey: zodBuffer,
encryptedGatewayServerCaCertificate: zodBuffer,
encryptedGatewayServerCaCertificateChain: zodBuffer,
encryptedGatewayClientCaPrivateKey: zodBuffer,
encryptedGatewayClientCaCertificate: zodBuffer,
encryptedGatewayClientCaCertificateChain: zodBuffer
});
export type TOrgGatewayConfigV2 = z.infer<typeof OrgGatewayConfigV2Schema>;
export type TOrgGatewayConfigV2Insert = Omit<z.input<typeof OrgGatewayConfigV2Schema>, TImmutableDBKeys>;
export type TOrgGatewayConfigV2Update = Partial<Omit<z.input<typeof OrgGatewayConfigV2Schema>, TImmutableDBKeys>>;
+22
View File
@@ -0,0 +1,22 @@
// Code generated by automation script, DO NOT EDIT.
// Automated by pulling database and generating zod schema
// To update. Just run npm run generate:schema
// Written by akhilmhdh.
import { z } from "zod";
import { TImmutableDBKeys } from "./models";
export const ProxiesSchema = z.object({
id: z.string().uuid(),
createdAt: z.date(),
updatedAt: z.date(),
orgId: z.string().uuid().nullable().optional(),
identityId: z.string().uuid().nullable().optional(),
name: z.string(),
ip: z.string()
});
export type TProxies = z.infer<typeof ProxiesSchema>;
export type TProxiesInsert = Omit<z.input<typeof ProxiesSchema>, TImmutableDBKeys>;
export type TProxiesUpdate = Partial<Omit<z.input<typeof ProxiesSchema>, TImmutableDBKeys>>;