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
misc: address comments
Sheen Capadngand9ebb53cbfa9
diff --git a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts b/backend/src/ee/services/gateway-v2/gateway-v2-service.tsindex 6180b66102..33d0e0ebc3 100644--- a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts+++ b/backend/src/ee/services/gateway-v2/gateway-v2-service.ts@@ -696,34 +696,15 @@ export const gatewayV2ServiceFactory = ({}};- const triggerHeartbeat = async ({ orgPermission, id }: { orgPermission: OrgServiceActor; id: string }) => {- const gateway = await gatewayV2DAL.findOne({ id, orgId: orgPermission.orgId });- if (!gateway) {- throw new NotFoundError({ message: `Gateway ${id} not found` });- }-- const { permission } = await permissionService.getOrgPermission({- actor: orgPermission.type,- actorId: orgPermission.id,- orgId: gateway.orgId,- actorAuthMethod: orgPermission.authMethod,- actorOrgId: orgPermission.orgId,- scope: OrganizationActionScope.Any- });-- ForbiddenError.from(permission).throwUnlessCan(- OrgPermissionGatewayActions.ListGateways,- OrgPermissionSubjects.Gateway- );-+ const $checkGatewayHealth = async (gatewayId: string) => {const gatewayV2ConnectionDetails = await getPlatformConnectionDetailsByGatewayId({- gatewayId: gateway.id,+ gatewayId,targetHost: "health-check",targetPort: 443});if (!gatewayV2ConnectionDetails) {- throw new NotFoundError({ message: `Gateway connection details for gateway ${gateway.id} not found.` });+ throw new NotFoundError({ message: `Gateway connection details for gateway ${gatewayId} not found.` });}const isGatewayReachable = await withGatewayV2Proxy(@@ -787,10 +768,33 @@ export const gatewayV2ServiceFactory = ({);if (!isGatewayReachable) {- throw new BadRequestError({ message: `Gateway ${gateway.id} is not reachable` });+ throw new BadRequestError({ message: `Gateway ${gatewayId} is not reachable` });}- await gatewayV2DAL.updateById(gateway.id, { heartbeat: new Date() });+ await gatewayV2DAL.updateById(gatewayId, { heartbeat: new Date() });+ };++ const triggerHeartbeat = async ({ orgPermission, id }: { orgPermission: OrgServiceActor; id: string }) => {+ const gateway = await gatewayV2DAL.findOne({ id, orgId: orgPermission.orgId });+ if (!gateway) {+ throw new NotFoundError({ message: `Gateway ${id} not found` });+ }++ const { permission } = await permissionService.getOrgPermission({+ actor: orgPermission.type,+ actorId: orgPermission.id,+ orgId: gateway.orgId,+ actorAuthMethod: orgPermission.authMethod,+ actorOrgId: orgPermission.orgId,+ scope: OrganizationActionScope.Any+ });++ ForbiddenError.from(permission).throwUnlessCan(+ OrgPermissionGatewayActions.ListGateways,+ OrgPermissionSubjects.Gateway+ );++ await $checkGatewayHealth(gateway.id);};const heartbeat = async ({ orgPermission }: { orgPermission: OrgServiceActor }) => {@@ -805,82 +809,7 @@ export const gatewayV2ServiceFactory = ({throw new NotFoundError({ message: `Gateway for identity ${orgPermission.id} not found.` });}- const gatewayV2ConnectionDetails = await getPlatformConnectionDetailsByGatewayId({- gatewayId: gateway.id,- targetHost: "health-check",- targetPort: 443- });-- if (!gatewayV2ConnectionDetails) {- throw new NotFoundError({ message: `Gateway connection details for gateway ${gateway.id} not found.` });- }-- const isGatewayReachable = await withGatewayV2Proxy(- async (port) => {- return new Promise<boolean>((resolve, reject) => {- const socket = new net.Socket();- let responseReceived = false;- let isResolved = false;-- // Set socket timeout- socket.setTimeout(10000);-- const cleanup = () => {- if (!socket.destroyed) {- socket.destroy();- }- };-- socket.on("data", (data: Buffer) => {- const response = data.toString().trim();- if (response === "PONG" && !isResolved) {- isResolved = true;- responseReceived = true;- cleanup();- resolve(true);- }- });-- socket.on("error", (err: Error) => {- if (!isResolved) {- isResolved = true;- cleanup();- reject(new Error(`TCP connection error: ${err.message}`));- }- });-- socket.on("timeout", () => {- if (!isResolved) {- isResolved = true;- cleanup();- reject(new Error("TCP connection timeout"));- }- });-- socket.on("close", () => {- if (!isResolved && !responseReceived) {- isResolved = true;- cleanup();- reject(new Error("Connection closed without receiving PONG"));- }- });-- socket.connect(port, "localhost");- });- },- {- protocol: GatewayProxyProtocol.Ping,- relayHost: gatewayV2ConnectionDetails.relayHost,- gateway: gatewayV2ConnectionDetails.gateway,- relay: gatewayV2ConnectionDetails.relay- }- );-- if (!isGatewayReachable) {- throw new BadRequestError({ message: `Gateway ${gateway.id} is not reachable` });- }-- await gatewayV2DAL.updateById(gateway.id, { heartbeat: new Date() });+ await $checkGatewayHealth(gateway.id);};const deleteGatewayById = async ({ orgPermission, id }: { orgPermission: OrgServiceActor; id: string }) => {