refactor: remove deprecated native integration error handling and streamline integration token saving process in API routes

This commit is contained in:
Victor Santos
2025-11-26 10:49:05 -03:00
parent 15c341bce1
commit 40c80f4b68
2 changed files with 63 additions and 81 deletions

View File

@@ -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 team@infisical.com.";
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 };
}
});

View File

@@ -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 team@infisical.com.";
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 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 { 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
// });
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: integrationAuth.projectId,
event: {
type: EventType.CREATE_INTEGRATION,
// eslint-disable-next-line
metadata: createIntegrationEventProperty
}
});
// 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.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 };
}
});