mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 20:27:43 +00:00
refactor: remove deprecated native integration error handling and streamline integration token saving process in API routes
This commit is contained in:
@@ -2,7 +2,6 @@ import { z } from "zod";
|
|||||||
|
|
||||||
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
|
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
|
||||||
import { ApiDocsTags, INTEGRATION_AUTH } from "@app/lib/api-docs";
|
import { ApiDocsTags, INTEGRATION_AUTH } from "@app/lib/api-docs";
|
||||||
import { ForbiddenRequestError } from "@app/lib/errors";
|
|
||||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
||||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
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";
|
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) => {
|
export const registerIntegrationAuthRouter = async (server: FastifyZodProvider) => {
|
||||||
server.route({
|
server.route({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
@@ -337,33 +333,27 @@ export const registerIntegrationAuthRouter = async (server: FastifyZodProvider)
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handler: async (_) => {
|
handler: async (req) => {
|
||||||
throw new ForbiddenRequestError({
|
const integrationAuth = await server.services.integrationAuth.saveIntegrationToken({
|
||||||
message: NATIVE_INTEGRATION_DEPRECATION_MESSAGE
|
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.
|
await server.services.auditLog.createAuditLog({
|
||||||
|
...req.auditLogInfo,
|
||||||
// const integrationAuth = await server.services.integrationAuth.saveIntegrationToken({
|
projectId: req.body.workspaceId,
|
||||||
// actorId: req.permission.id,
|
event: {
|
||||||
// actor: req.permission.type,
|
type: EventType.AUTHORIZE_INTEGRATION,
|
||||||
// actorAuthMethod: req.permission.authMethod,
|
metadata: {
|
||||||
// actorOrgId: req.permission.orgId,
|
integration: integrationAuth.integration
|
||||||
// projectId: req.body.workspaceId,
|
}
|
||||||
// ...req.body
|
}
|
||||||
// });
|
});
|
||||||
|
return { integrationAuth };
|
||||||
// await server.services.auditLog.createAuditLog({
|
|
||||||
// ...req.auditLogInfo,
|
|
||||||
// projectId: req.body.workspaceId,
|
|
||||||
// event: {
|
|
||||||
// type: EventType.AUTHORIZE_INTEGRATION,
|
|
||||||
// metadata: {
|
|
||||||
// integration: integrationAuth.integration
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// return { integrationAuth };
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,19 +3,17 @@ import { z } from "zod";
|
|||||||
import { IntegrationsSchema } from "@app/db/schemas";
|
import { IntegrationsSchema } from "@app/db/schemas";
|
||||||
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
|
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
|
||||||
import { ApiDocsTags, INTEGRATION } from "@app/lib/api-docs";
|
import { ApiDocsTags, INTEGRATION } from "@app/lib/api-docs";
|
||||||
import { ForbiddenRequestError } from "@app/lib/errors";
|
|
||||||
import { removeTrailingSlash, shake } from "@app/lib/fn";
|
import { removeTrailingSlash, shake } from "@app/lib/fn";
|
||||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
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 { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
import { IntegrationMetadataSchema } from "@app/services/integration/integration-schema";
|
import { IntegrationMetadataSchema } from "@app/services/integration/integration-schema";
|
||||||
import { Integrations } from "@app/services/integration-auth/integration-list";
|
import { Integrations } from "@app/services/integration-auth/integration-list";
|
||||||
|
import { PostHogEventTypes, TIntegrationCreatedEvent } from "@app/services/telemetry/telemetry-types";
|
||||||
|
|
||||||
import {} from "../sanitizedSchemas";
|
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) => {
|
export const registerIntegrationRouter = async (server: FastifyZodProvider) => {
|
||||||
server.route({
|
server.route({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -68,58 +66,52 @@ export const registerIntegrationRouter = async (server: FastifyZodProvider) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
|
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
|
||||||
handler: async (_) => {
|
handler: async (req) => {
|
||||||
throw new ForbiddenRequestError({
|
const { integration, integrationAuth } = await server.services.integration.createIntegration({
|
||||||
message: NATIVE_INTEGRATION_DEPRECATION_MESSAGE
|
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({
|
await server.services.auditLog.createAuditLog({
|
||||||
// actorId: req.permission.id,
|
...req.auditLogInfo,
|
||||||
// actor: req.permission.type,
|
projectId: integrationAuth.projectId,
|
||||||
// actorAuthMethod: req.permission.authMethod,
|
event: {
|
||||||
// actorOrgId: req.permission.orgId,
|
type: EventType.CREATE_INTEGRATION,
|
||||||
// ...req.body
|
// eslint-disable-next-line
|
||||||
// });
|
metadata: createIntegrationEventProperty
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// const createIntegrationEventProperty = shake({
|
await server.services.telemetry.sendPostHogEvents({
|
||||||
// integrationId: integration.id.toString(),
|
event: PostHogEventTypes.IntegrationCreated,
|
||||||
// integration: integration.integration,
|
organizationId: req.permission.orgId,
|
||||||
// environment: req.body.sourceEnvironment,
|
distinctId: getTelemetryDistinctId(req),
|
||||||
// secretPath: req.body.secretPath,
|
properties: {
|
||||||
// url: integration.url,
|
...createIntegrationEventProperty,
|
||||||
// app: integration.app,
|
projectId: integrationAuth.projectId,
|
||||||
// appId: integration.appId,
|
...req.auditLogInfo
|
||||||
// targetEnvironment: integration.targetEnvironment,
|
}
|
||||||
// targetEnvironmentId: integration.targetEnvironmentId,
|
});
|
||||||
// targetService: integration.targetService,
|
return { integration };
|
||||||
// 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 };
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user