Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
refactor: add enrollmentTokenStatus to gateway list, remove GET /enrollment-tokens
bernie-g50d4967f9748
diff --git a/backend/src/ee/routes/v2/gateway-router.ts b/backend/src/ee/routes/v2/gateway-router.tsindex 795e4375f1..1b8b620577 100644--- a/backend/src/ee/routes/v2/gateway-router.ts+++ b/backend/src/ee/routes/v2/gateway-router.ts@@ -106,7 +106,8 @@ export const registerGatewayV2Router = async (server: FastifyZodProvider) => {response: {200: SanitizedGatewayV2Schema.extend({identity: z.object({ name: z.string(), id: z.string() }).nullable(),- connectedResourcesCount: z.number()+ connectedResourcesCount: z.number(),+ enrollmentTokenStatus: z.enum(["pending", "expired"]).nullable()}).array()}},@@ -325,20 +326,6 @@ export const registerGatewayV2Router = async (server: FastifyZodProvider) => {}});- server.route({- method: "GET",- url: "/enrollment-tokens",- config: { rateLimit: readLimit },- schema: {- operationId: "listGatewayEnrollmentTokens",- response: { 200: SanitizedEnrollmentTokenSchema.array() }- },- onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),- handler: async (req) => {- return server.services.gatewayV2.listEnrollmentTokens({ orgPermission: req.permission });- }- });-server.route({method: "DELETE",url: "/enrollment-tokens/:tokenId",diff --git a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts b/backend/src/ee/services/gateway-v2/gateway-v2-service.tsindex a6fe1edbbd..806617e56e 100644--- a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts+++ b/backend/src/ee/services/gateway-v2/gateway-v2-service.ts@@ -350,9 +350,26 @@ export const gatewayV2ServiceFactory = ({countMap.set(id, (countMap.get(id) ?? 0) + count);}+ // Check enrollment token status for each gateway+ const allTokens = await gatewayEnrollmentTokenDAL.find({ orgId: orgPermission.orgId });+ const now = new Date();+ const tokenStatusMap = new Map<string, "pending" | "expired">();+ for (const token of allTokens) {+ if (token.usedAt || !token.gatewayId) continue;+ const isExpired = token.expiresAt <= now;+ const current = tokenStatusMap.get(token.gatewayId);+ // A non-expired token takes priority over an expired one+ if (!isExpired) {+ tokenStatusMap.set(token.gatewayId, "pending");+ } else if (!current) {+ tokenStatusMap.set(token.gatewayId, "expired");+ }+ }+return gateways.map((gateway) => ({...gateway,- connectedResourcesCount: countMap.get(gateway.id) ?? 0+ connectedResourcesCount: countMap.get(gateway.id) ?? 0,+ enrollmentTokenStatus: tokenStatusMap.get(gateway.id) ?? null}));};@@ -1230,25 +1247,6 @@ export const gatewayV2ServiceFactory = ({return { ...tokenRecord, token: plainToken, gatewayId: gateway.id };};- const listEnrollmentTokens = async ({ orgPermission }: { orgPermission: OrgServiceActor }) => {- const { permission } = await permissionService.getOrgPermission({- actor: orgPermission.type,- actorId: orgPermission.id,- orgId: orgPermission.orgId,- actorAuthMethod: orgPermission.authMethod,- actorOrgId: orgPermission.orgId,- scope: OrganizationActionScope.Any- });-- ForbiddenError.from(permission).throwUnlessCan(- OrgPermissionGatewayActions.ListGateways,- OrgPermissionSubjects.Gateway- );-- const tokens = await gatewayEnrollmentTokenDAL.find({ orgId: orgPermission.orgId });- return tokens.filter((t) => !t.usedAt).map(({ tokenHash: _, ...rest }) => rest);- };-const deleteEnrollmentToken = async ({orgPermission,tokenId@@ -1511,7 +1509,6 @@ export const gatewayV2ServiceFactory = ({getConnectedResources,getGatewayById,createEnrollmentToken,- listEnrollmentTokens,deleteEnrollmentToken,enrollGateway,reEnrollGatewaydiff --git a/frontend/src/hooks/api/gateways-v2/types.ts b/frontend/src/hooks/api/gateways-v2/types.tsindex 10ce07795d..6821df819e 100644--- a/frontend/src/hooks/api/gateways-v2/types.ts+++ b/frontend/src/hooks/api/gateways-v2/types.ts@@ -16,6 +16,7 @@ export type TGatewayV2 = {name: string;id: string;} | null;+ enrollmentTokenStatus: "pending" | "expired" | null;};export type TGatewayEnrollmentToken = {diff --git a/frontend/src/hooks/api/gateways/queries.tsx b/frontend/src/hooks/api/gateways/queries.tsxindex 8bfb52fe22..1817139909 100644--- a/frontend/src/hooks/api/gateways/queries.tsx+++ b/frontend/src/hooks/api/gateways/queries.tsx@@ -2,7 +2,7 @@ import { queryOptions } from "@tanstack/react-query";import { apiRequest } from "@app/config/request";-import { TGatewayEnrollmentToken, TGatewayV2 } from "../gateways-v2/types";+import { TGatewayV2 } from "../gateways-v2/types";import { TGateway } from "./types";export const gatewaysQueryKeys = {@@ -34,29 +34,11 @@ export const gatewaysQueryKeys = {queryOptions({queryKey: gatewaysQueryKeys.listWithTokensKey(),queryFn: async () => {- const [{ data }, { data: dataV2 }, { data: enrollmentTokens }] = await Promise.all([+ const [{ data }, { data: dataV2 }] = await Promise.all([apiRequest.get<{ gateways: TGateway[] }>("/api/v1/gateways"),- apiRequest.get<TGatewayV2[]>("/api/v2/gateways"),- apiRequest.get<TGatewayEnrollmentToken[]>("/api/v2/gateways/enrollment-tokens")+ apiRequest.get<TGatewayV2[]>("/api/v2/gateways")]);- const now = new Date();- const unusedTokens = enrollmentTokens.filter((t) => !t.usedAt);-- // Gateways with a non-expired unused enrollment token (pending initial enrollment or re-enrollment)- const pendingGatewayIds = new Set(- unusedTokens- .filter((t) => t.gatewayId && new Date(t.expiresAt) > now)- .map((t) => t.gatewayId)- );-- // Gateways whose only unused token is expired- const expiredGatewayIds = new Set(- unusedTokens- .filter((t) => t.gatewayId && new Date(t.expiresAt) <= now && !pendingGatewayIds.has(t.gatewayId))- .map((t) => t.gatewayId)- );-return [...data.gateways.map((g) => ({...g,@@ -67,9 +49,9 @@ export const gatewaysQueryKeys = {})),...dataV2.map((g) => {const hasHeartbeat = !!g.heartbeat;- const isPending = pendingGatewayIds.has(g.id) && !hasHeartbeat;- const hasReEnrollToken = pendingGatewayIds.has(g.id) && hasHeartbeat;- const isExpired = expiredGatewayIds.has(g.id) && !hasHeartbeat;+ const isPending = g.enrollmentTokenStatus === "pending" && !hasHeartbeat;+ const hasReEnrollToken = g.enrollmentTokenStatus === "pending" && hasHeartbeat;+ const isExpired = g.enrollmentTokenStatus === "expired" && !hasHeartbeat;return {...g,