From 6e6e4a29547a244bfff017fd1fb187054a627b60 Mon Sep 17 00:00:00 2001 From: John Smith Date: Sun, 1 Dec 2024 14:32:36 +1030 Subject: [PATCH] chore: Remove service metadata (#176) --- control-plane/src/modules/contract.ts | 17 ----- control-plane/src/modules/data.ts | 20 ------ control-plane/src/modules/router.ts | 25 -------- control-plane/src/modules/service-metadata.ts | 63 ------------------- 4 files changed, 125 deletions(-) delete mode 100644 control-plane/src/modules/service-metadata.ts diff --git a/control-plane/src/modules/contract.ts b/control-plane/src/modules/contract.ts index 9be2f63b..98cc5888 100644 --- a/control-plane/src/modules/contract.ts +++ b/control-plane/src/modules/contract.ts @@ -756,23 +756,6 @@ export const definition = { messageId: z.string(), }), }, - storeServiceMetadata: { - method: "PUT", - path: "/clusters/:clusterId/services/:service/keys/:key", - headers: z.object({ authorization: z.string() }), - body: z.object({ - value: z.string(), - }), - pathParams: z.object({ - clusterId: z.string(), - service: z.string(), - key: z.string(), - }), - responses: { - 204: z.undefined(), - 401: z.undefined(), - }, - }, getClusterExport: { method: "GET", path: "/clusters/:clusterId/export", diff --git a/control-plane/src/modules/data.ts b/control-plane/src/modules/data.ts index d0df7a0d..70c1abe9 100644 --- a/control-plane/src/modules/data.ts +++ b/control-plane/src/modules/data.ts @@ -220,26 +220,6 @@ export const integrations = pgTable( }), ); -export const serviceMetadata = pgTable( - "service_metadata", - { - cluster_id: varchar("cluster_id") - .references(() => clusters.id) - .notNull(), - service: varchar("service", { length: 1024 }).notNull(), - key: text("status", { - enum: ["incoming-webhook-token"], - }).notNull(), - value: text("value").notNull(), - }, - (table) => ({ - pk: primaryKey({ - columns: [table.cluster_id, table.service, table.key], - name: "service_metadata_cluster_id_service_key", - }), - }), -); - export const workflowMetadata = pgTable( "workflow_metadata", { diff --git a/control-plane/src/modules/router.ts b/control-plane/src/modules/router.ts index 1b9a2b7b..0bbd1f3b 100644 --- a/control-plane/src/modules/router.ts +++ b/control-plane/src/modules/router.ts @@ -8,7 +8,6 @@ import { contract } from "./contract"; import * as data from "./data"; import * as management from "./management"; import * as events from "./observability/events"; -import { storeServiceMetadata } from "./service-metadata"; import { assertGenericMessage, editHumanMessage, @@ -339,30 +338,6 @@ export const router = initServer().router(contract, { body: messages.upserted, }; }, - storeServiceMetadata: async (request) => { - const machine = request.request.getAuth().isMachine(); - - const { clusterId, service, key } = request.params; - const { value } = request.body; - - if (machine.clusterId !== clusterId) { - return { - status: 401, - }; - } - - await storeServiceMetadata({ - clusterId, - key, - value, - service, - }); - - return { - status: 204, - body: undefined, - }; - }, getClusterExport: async (request) => { const { clusterId } = request.params; diff --git a/control-plane/src/modules/service-metadata.ts b/control-plane/src/modules/service-metadata.ts deleted file mode 100644 index 97598bc8..00000000 --- a/control-plane/src/modules/service-metadata.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { z } from "zod"; -import { db, serviceMetadata } from "./data"; -import { and, eq } from "drizzle-orm"; - -const keySchema = z.enum(["incoming-webhook-token"]); - -export const storeServiceMetadata = async ({ - clusterId, - key, - value, - service, -}: { - service: string; - clusterId: string; - key: string; - value: string; -}) => { - await db - .insert(serviceMetadata) - .values([ - { - service, - cluster_id: clusterId, - key: keySchema.parse(key), - value, - }, - ]) - .onConflictDoUpdate({ - target: [ - serviceMetadata.cluster_id, - serviceMetadata.service, - serviceMetadata.key, - ], - set: { - key: keySchema.parse(key), - value, - }, - }); -}; - -export const getServiceMetadata = async ({ - clusterId, - service, - key, -}: { - service: string; - clusterId: string; - key: string; -}) => { - return db - .select({ - key: serviceMetadata.key, - value: serviceMetadata.value, - }) - .from(serviceMetadata) - .where( - and( - eq(serviceMetadata.cluster_id, clusterId), - eq(serviceMetadata.service, service), - eq(serviceMetadata.key, keySchema.parse(key)), - ), - ); -};