Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

misc: re-added route except POST

Sheen Capadnganbf2deddc931a
diff --git a/backend/src/ee/routes/v1/gateway-router.ts b/backend/src/ee/routes/v1/gateway-router.ts
new file mode 100644
index 0000000000..00fdecedc4
--- /dev/null
+++ b/backend/src/ee/routes/v1/gateway-router.ts
@@ -0,0 +1,215 @@
+import { z } from "zod";
+
+import { GatewaysSchema } from "@app/db/schemas";
+import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
+import { slugSchema } from "@app/server/lib/schemas";
+import { getTelemetryDistinctId } from "@app/server/lib/telemetry";
+import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
+import { AuthMode } from "@app/services/auth/auth-type";
+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
+
+const SanitizedGatewaySchema = GatewaysSchema.pick({
+ id: true,
+ identityId: true,
+ name: true,
+ createdAt: true,
+ updatedAt: true,
+ issuedAt: true,
+ serialNumber: true,
+ heartbeat: true
+});
+
+export const registerGatewayRouter = async (server: FastifyZodProvider) => {
+ server.route({
+ method: "POST",
+ url: "/heartbeat",
+ config: {
+ rateLimit: writeLimit
+ },
+ schema: {
+ response: {
+ 200: z.object({
+ message: z.string()
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.IDENTITY_ACCESS_TOKEN]),
+ handler: async (req) => {
+ await server.services.gateway.heartbeat({
+ orgPermission: req.permission
+ });
+ return { message: "Successfully registered heartbeat" };
+ }
+ });
+
+ server.route({
+ method: "GET",
+ url: "/",
+ config: {
+ rateLimit: readLimit
+ },
+ schema: {
+ querystring: z.object({
+ projectId: z.string().optional()
+ }),
+ response: {
+ 200: z.object({
+ gateways: SanitizedGatewaySchema.extend({
+ identity: z.object({
+ name: z.string(),
+ id: z.string()
+ })
+ }).array()
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.IDENTITY_ACCESS_TOKEN, AuthMode.JWT]),
+ handler: async (req) => {
+ const gateways = await server.services.gateway.listGateways({
+ orgPermission: req.permission
+ });
+ return { gateways };
+ }
+ });
+
+ server.route({
+ method: "GET",
+ url: "/projects/:projectId",
+ config: {
+ rateLimit: readLimit
+ },
+ schema: {
+ params: z.object({
+ projectId: z.string()
+ }),
+ response: {
+ 200: z.object({
+ gateways: SanitizedGatewaySchema.extend({
+ identity: z.object({
+ name: z.string(),
+ id: z.string()
+ })
+ }).array()
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.IDENTITY_ACCESS_TOKEN, AuthMode.JWT]),
+ handler: async (req) => {
+ const gateways = await server.services.gateway.listGateways({
+ orgPermission: req.permission
+ });
+ return { gateways };
+ }
+ });
+
+ server.route({
+ method: "GET",
+ url: "/:id",
+ config: {
+ rateLimit: readLimit
+ },
+ schema: {
+ params: z.object({
+ id: z.string()
+ }),
+ response: {
+ 200: z.object({
+ gateway: SanitizedGatewaySchema.extend({
+ identity: z.object({
+ name: z.string(),
+ id: z.string()
+ })
+ })
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.IDENTITY_ACCESS_TOKEN, AuthMode.JWT]),
+ handler: async (req) => {
+ const gateway = await server.services.gateway.getGatewayById({
+ orgPermission: req.permission,
+ id: req.params.id
+ });
+ return { gateway };
+ }
+ });
+
+ server.route({
+ method: "PATCH",
+ url: "/:id",
+ config: {
+ rateLimit: writeLimit
+ },
+ schema: {
+ params: z.object({
+ id: z.string()
+ }),
+ body: z.object({
+ name: slugSchema({ field: "name" }).optional()
+ }),
+ response: {
+ 200: z.object({
+ gateway: SanitizedGatewaySchema
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.IDENTITY_ACCESS_TOKEN, AuthMode.JWT]),
+ handler: async (req) => {
+ const gateway = await server.services.gateway.updateGatewayById({
+ orgPermission: req.permission,
+ id: req.params.id,
+ name: req.body.name
+ });
+
+ void server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.GatewayUpdated,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ gatewayId: gateway.id
+ }
+ })
+ .catch(() => {});
+
+ return { gateway };
+ }
+ });
+
+ server.route({
+ method: "DELETE",
+ url: "/:id",
+ config: {
+ rateLimit: writeLimit
+ },
+ schema: {
+ params: z.object({
+ id: z.string()
+ }),
+ response: {
+ 200: z.object({
+ gateway: SanitizedGatewaySchema
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.IDENTITY_ACCESS_TOKEN, AuthMode.JWT]),
+ handler: async (req) => {
+ const gateway = await server.services.gateway.deleteGatewayById({
+ orgPermission: req.permission,
+ id: req.params.id
+ });
+
+ void server.services.telemetry
+ .sendPostHogEvents({
+ event: PostHogEventTypes.GatewayDeleted,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ gatewayId: gateway.id
+ }
+ })
+ .catch(() => {});
+
+ return { gateway };
+ }
+ });
+};
diff --git a/backend/src/ee/routes/v1/index.ts b/backend/src/ee/routes/v1/index.ts
index d580356b72..e01b59e78e 100644
--- a/backend/src/ee/routes/v1/index.ts
+++ b/backend/src/ee/routes/v1/index.ts
@@ -19,6 +19,7 @@ import { registerEmailDomainRouter } from "./email-domain-router";
import { registerExternalKmsRouter } from "./external-kms-router";
import { EXTERNAL_KMS_REGISTER_ROUTER_MAP } from "./external-kms-routers";
import { registerGatewayPoolRouter } from "./gateway-pool-router";
+import { registerGatewayRouter } from "./gateway-router";
import { registerGithubOrgSyncRouter } from "./github-org-sync-router";
import { registerGroupRouter } from "./group-router";
import { registerHoneyTokenRouter } from "./honey-token-router";
@@ -119,6 +120,7 @@ export const registerV1EERoutes = async (server: FastifyZodProvider) => {
{ prefix: "/dynamic-secrets" }
);
+ await server.register(registerGatewayRouter, { prefix: "/gateways" });
await server.register(registerGatewayPoolRouter, { prefix: "/gateway-pools" });
await server.register(registerRelayRouter, { prefix: "/relays" });
await server.register(registerGithubOrgSyncRouter, { prefix: "/github-org-sync-config" });