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: remove deprecated native integration error handling and streamline integration token saving process in API routes
Victor Santos40c80f4b6829
diff --git a/backend/src/server/routes/v1/integration-auth-router.ts b/backend/src/server/routes/v1/integration-auth-router.tsindex 40bb8fa13e..e5156724de 100644--- a/backend/src/server/routes/v1/integration-auth-router.ts+++ b/backend/src/server/routes/v1/integration-auth-router.ts@@ -2,7 +2,6 @@ import { z } from "zod";import { EventType } from "@app/ee/services/audit-log/audit-log-types";import { ApiDocsTags, INTEGRATION_AUTH } from "@app/lib/api-docs";-import { ForbiddenRequestError } from "@app/lib/errors";import { readLimit, writeLimit } from "@app/server/config/rateLimiter";import { verifyAuth } from "@app/server/plugins/auth/verify-auth";import { AuthMode } from "@app/services/auth/auth-type";@@ -11,9 +10,6 @@ import { Integrations } from "@app/services/integration-auth/integration-list";import { integrationAuthPubSchema } from "../sanitizedSchemas";-const NATIVE_INTEGRATION_DEPRECATION_MESSAGE =- "We're moving Native Integrations to Secret Syncs. Check the documentation at https://infisical.com/docs/integrations/secret-syncs/overview. If the integration you need isn't available in the Secret Syncs, please get in touch with us at [email protected].";-export const registerIntegrationAuthRouter = async (server: FastifyZodProvider) => {server.route({method: "GET",@@ -337,33 +333,27 @@ export const registerIntegrationAuthRouter = async (server: FastifyZodProvider)})}},- handler: async (_) => {- throw new ForbiddenRequestError({- message: NATIVE_INTEGRATION_DEPRECATION_MESSAGE+ handler: async (req) => {+ const integrationAuth = await server.services.integrationAuth.saveIntegrationToken({+ actorId: req.permission.id,+ actor: req.permission.type,+ actorAuthMethod: req.permission.authMethod,+ actorOrgId: req.permission.orgId,+ projectId: req.body.workspaceId,+ ...req.body});- // We are keeping the old response commented out for an easy revert on the API if we need to before the full phase out.-- // const integrationAuth = await server.services.integrationAuth.saveIntegrationToken({- // actorId: req.permission.id,- // actor: req.permission.type,- // actorAuthMethod: req.permission.authMethod,- // actorOrgId: req.permission.orgId,- // projectId: req.body.workspaceId,- // ...req.body- // });-- // await server.services.auditLog.createAuditLog({- // ...req.auditLogInfo,- // projectId: req.body.workspaceId,- // event: {- // type: EventType.AUTHORIZE_INTEGRATION,- // metadata: {- // integration: integrationAuth.integration- // }- // }- // });- // return { integrationAuth };+ await server.services.auditLog.createAuditLog({+ ...req.auditLogInfo,+ projectId: req.body.workspaceId,+ event: {+ type: EventType.AUTHORIZE_INTEGRATION,+ metadata: {+ integration: integrationAuth.integration+ }+ }+ });+ return { integrationAuth };}});diff --git a/backend/src/server/routes/v1/integration-router.ts b/backend/src/server/routes/v1/integration-router.tsindex 183c5a38ba..95477c3419 100644--- a/backend/src/server/routes/v1/integration-router.ts+++ b/backend/src/server/routes/v1/integration-router.ts@@ -3,19 +3,17 @@ import { z } from "zod";import { IntegrationsSchema } from "@app/db/schemas";import { EventType } from "@app/ee/services/audit-log/audit-log-types";import { ApiDocsTags, INTEGRATION } from "@app/lib/api-docs";-import { ForbiddenRequestError } from "@app/lib/errors";import { removeTrailingSlash, shake } from "@app/lib/fn";import { readLimit, writeLimit } from "@app/server/config/rateLimiter";+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 { IntegrationMetadataSchema } from "@app/services/integration/integration-schema";import { Integrations } from "@app/services/integration-auth/integration-list";+import { PostHogEventTypes, TIntegrationCreatedEvent } from "@app/services/telemetry/telemetry-types";import {} from "../sanitizedSchemas";-const NATIVE_INTEGRATION_DEPRECATION_MESSAGE =- "We're moving Native Integrations to Secret Syncs. Check the documentation at https://infisical.com/docs/integrations/secret-syncs/overview. If the integration you need isn't available in the Secret Syncs, please get in touch with us at [email protected].";-export const registerIntegrationRouter = async (server: FastifyZodProvider) => {server.route({method: "POST",@@ -68,58 +66,52 @@ export const registerIntegrationRouter = async (server: FastifyZodProvider) => {}},onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),- handler: async (_) => {- throw new ForbiddenRequestError({- message: NATIVE_INTEGRATION_DEPRECATION_MESSAGE+ handler: async (req) => {+ const { integration, integrationAuth } = await server.services.integration.createIntegration({+ actorId: req.permission.id,+ actor: req.permission.type,+ actorAuthMethod: req.permission.authMethod,+ actorOrgId: req.permission.orgId,+ ...req.body});- // We are keeping the old response commented out for an easy revert on the API if we need to before the full phase out.-- // const { integration, integrationAuth } = await server.services.integration.createIntegration({- // actorId: req.permission.id,- // actor: req.permission.type,- // actorAuthMethod: req.permission.authMethod,- // actorOrgId: req.permission.orgId,- // ...req.body- // });-- // const createIntegrationEventProperty = shake({- // integrationId: integration.id.toString(),- // integration: integration.integration,- // environment: req.body.sourceEnvironment,- // secretPath: req.body.secretPath,- // url: integration.url,- // app: integration.app,- // appId: integration.appId,- // targetEnvironment: integration.targetEnvironment,- // targetEnvironmentId: integration.targetEnvironmentId,- // targetService: integration.targetService,- // targetServiceId: integration.targetServiceId,- // path: integration.path,- // region: integration.region- // }) as TIntegrationCreatedEvent["properties"];+ const createIntegrationEventProperty = shake({+ integrationId: integration.id.toString(),+ integration: integration.integration,+ environment: req.body.sourceEnvironment,+ secretPath: req.body.secretPath,+ url: integration.url,+ app: integration.app,+ appId: integration.appId,+ targetEnvironment: integration.targetEnvironment,+ targetEnvironmentId: integration.targetEnvironmentId,+ targetService: integration.targetService,+ targetServiceId: integration.targetServiceId,+ path: integration.path,+ region: integration.region+ }) as TIntegrationCreatedEvent["properties"];- // await server.services.auditLog.createAuditLog({- // ...req.auditLogInfo,- // projectId: integrationAuth.projectId,- // event: {- // type: EventType.CREATE_INTEGRATION,- // // eslint-disable-next-line- // metadata: createIntegrationEventProperty- // }- // });+ await server.services.auditLog.createAuditLog({+ ...req.auditLogInfo,+ projectId: integrationAuth.projectId,+ event: {+ type: EventType.CREATE_INTEGRATION,+ // eslint-disable-next-line+ metadata: createIntegrationEventProperty+ }+ });- // await server.services.telemetry.sendPostHogEvents({- // event: PostHogEventTypes.IntegrationCreated,- // organizationId: req.permission.orgId,- // distinctId: getTelemetryDistinctId(req),- // properties: {- // ...createIntegrationEventProperty,- // projectId: integrationAuth.projectId,- // ...req.auditLogInfo- // }- // });- // return { integration };+ await server.services.telemetry.sendPostHogEvents({+ event: PostHogEventTypes.IntegrationCreated,+ organizationId: req.permission.orgId,+ distinctId: getTelemetryDistinctId(req),+ properties: {+ ...createIntegrationEventProperty,+ projectId: integrationAuth.projectId,+ ...req.auditLogInfo+ }+ });+ return { integration };}});