diff --git a/backend/src/queue/queue-service.ts b/backend/src/queue/queue-service.ts index bcef34d4f..f4c49d15a 100644 --- a/backend/src/queue/queue-service.ts +++ b/backend/src/queue/queue-service.ts @@ -22,6 +22,7 @@ import { crypto } from "@app/lib/crypto"; import { logger } from "@app/lib/logger"; import { QueueWorkerProfile } from "@app/lib/types"; import { CaType } from "@app/services/certificate-authority/certificate-authority-enums"; +import { ExternalPlatforms } from "@app/services/external-migration/external-migration-types"; import { TFailedIntegrationSyncEmailsPayload, TIntegrationSyncPayload, @@ -228,6 +229,7 @@ export type TQueueJobTypes = { name: QueueJobs.ImportSecretsFromExternalSource; payload: { actorEmail: string; + importType: ExternalPlatforms; data: { iv: string; tag: string; diff --git a/backend/src/services/external-migration/external-migration-fns/vault.ts b/backend/src/services/external-migration/external-migration-fns/vault.ts index 197102f82..b512ff11a 100644 --- a/backend/src/services/external-migration/external-migration-fns/vault.ts +++ b/backend/src/services/external-migration/external-migration-fns/vault.ts @@ -17,25 +17,16 @@ type VaultData = { const vaultFactory = () => { const getMounts = async (request: AxiosInstance) => { const response = await request - .get< - Record< - string, - { - accessor: string; - options: { - version?: string; - } | null; - type: string; - } - > - >("/v1/sys/mounts") + .get<{ + data: Record; + }>("/v1/sys/mounts") .catch((err) => { if (axios.isAxiosError(err)) { logger.error(err.response?.data, "External migration: Failed to get Vault mounts"); } throw err; }); - return response.data; + return response.data.data; }; const getPaths = async ( diff --git a/backend/src/services/external-migration/external-migration-queue.ts b/backend/src/services/external-migration/external-migration-queue.ts index 8bde91aa5..b4974d2ae 100644 --- a/backend/src/services/external-migration/external-migration-queue.ts +++ b/backend/src/services/external-migration/external-migration-queue.ts @@ -19,7 +19,7 @@ import { TSecretVersionV2DALFactory } from "../secret-v2-bridge/secret-version-d import { TSecretVersionV2TagDALFactory } from "../secret-v2-bridge/secret-version-tag-dal"; import { SmtpTemplates, TSmtpService } from "../smtp/smtp-service"; import { importDataIntoInfisicalFn } from "./external-migration-fns"; -import { ExternalPlatforms, ImportType, TImportInfisicalDataCreate } from "./external-migration-types"; +import { ExternalPlatforms, TImportInfisicalDataCreate } from "./external-migration-types"; export type TExternalMigrationQueueFactoryDep = { smtpService: TSmtpService; @@ -66,8 +66,8 @@ export const externalMigrationQueueFactory = ({ }: TExternalMigrationQueueFactoryDep) => { const startImport = async (dto: { actorEmail: string; + importType: ExternalPlatforms; data: { - importType: ImportType; iv: string; tag: string; ciphertext: string; @@ -87,14 +87,14 @@ export const externalMigrationQueueFactory = ({ }; queueService.start(QueueName.ImportSecretsFromExternalSource, async (job) => { - try { - const { data, actorEmail } = job.data; + const { data, actorEmail, importType } = job.data; + try { await smtpService.sendMail({ recipients: [actorEmail], subjectLine: "Infisical import started", substitutions: { - provider: ExternalPlatforms.EnvKey + provider: importType }, template: SmtpTemplates.ExternalImportStarted }); @@ -141,7 +141,7 @@ export const externalMigrationQueueFactory = ({ recipients: [actorEmail], subjectLine: "Infisical import successful", substitutions: { - provider: ExternalPlatforms.EnvKey + provider: importType }, template: SmtpTemplates.ExternalImportSuccessful }); @@ -150,7 +150,7 @@ export const externalMigrationQueueFactory = ({ recipients: [job.data.actorEmail], subjectLine: "Infisical import failed", substitutions: { - provider: ExternalPlatforms.EnvKey, + provider: importType, // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment error: (err as any)?.message || "Unknown error" }, diff --git a/backend/src/services/external-migration/external-migration-service.ts b/backend/src/services/external-migration/external-migration-service.ts index 766b6cef4..3bbb88f5b 100644 --- a/backend/src/services/external-migration/external-migration-service.ts +++ b/backend/src/services/external-migration/external-migration-service.ts @@ -6,7 +6,7 @@ import { BadRequestError, ForbiddenRequestError } from "@app/lib/errors"; import { TUserDALFactory } from "../user/user-dal"; import { decryptEnvKeyDataFn, importVaultDataFn, parseEnvKeyDataFn } from "./external-migration-fns"; import { TExternalMigrationQueueFactory } from "./external-migration-queue"; -import { ImportType, TImportEnvKeyDataDTO, TImportVaultDataDTO } from "./external-migration-types"; +import { ExternalPlatforms, TImportEnvKeyDataDTO, TImportVaultDataDTO } from "./external-migration-types"; type TExternalMigrationServiceFactoryDep = { permissionService: TPermissionServiceFactory; @@ -60,8 +60,8 @@ export const externalMigrationServiceFactory = ({ await externalMigrationQueue.startImport({ actorEmail: user.email!, + importType: ExternalPlatforms.EnvKey, data: { - importType: ImportType.EnvKey, ...encrypted } }); @@ -110,8 +110,8 @@ export const externalMigrationServiceFactory = ({ await externalMigrationQueue.startImport({ actorEmail: user.email!, + importType: ExternalPlatforms.Vault, data: { - importType: ImportType.Vault, ...encrypted } }); diff --git a/backend/src/services/external-migration/external-migration-types.ts b/backend/src/services/external-migration/external-migration-types.ts index 89589d674..7c0d4c9ea 100644 --- a/backend/src/services/external-migration/external-migration-types.ts +++ b/backend/src/services/external-migration/external-migration-types.ts @@ -2,11 +2,6 @@ import { TOrgPermission } from "@app/lib/types"; import { ActorAuthMethod, ActorType } from "../auth/auth-type"; -export enum ImportType { - EnvKey = "envkey", - Vault = "vault" -} - export enum VaultMappingType { Namespace = "namespace", KeyVault = "key-vault" @@ -112,5 +107,6 @@ export type TEnvKeyExportJSON = { }; export enum ExternalPlatforms { - EnvKey = "EnvKey" + EnvKey = "EnvKey", + Vault = "Vault" }