mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-10 07:28:50 +00:00
feat(notifications): import status update notifications
This commit is contained in:
@@ -231,6 +231,8 @@ export type TQueueJobTypes = {
|
|||||||
[QueueName.ImportSecretsFromExternalSource]: {
|
[QueueName.ImportSecretsFromExternalSource]: {
|
||||||
name: QueueJobs.ImportSecretsFromExternalSource;
|
name: QueueJobs.ImportSecretsFromExternalSource;
|
||||||
payload: {
|
payload: {
|
||||||
|
orgId: string;
|
||||||
|
actorId: string;
|
||||||
actorEmail: string;
|
actorEmail: string;
|
||||||
importType: ExternalPlatforms;
|
importType: ExternalPlatforms;
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -1815,7 +1815,8 @@ export const registerRoutes = async (
|
|||||||
secretV2BridgeService,
|
secretV2BridgeService,
|
||||||
resourceMetadataDAL,
|
resourceMetadataDAL,
|
||||||
folderCommitService,
|
folderCommitService,
|
||||||
folderVersionDAL
|
folderVersionDAL,
|
||||||
|
notificationService
|
||||||
});
|
});
|
||||||
|
|
||||||
const migrationService = externalMigrationServiceFactory({
|
const migrationService = externalMigrationServiceFactory({
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
|
|||||||
|
|
||||||
import { TFolderCommitServiceFactory } from "../folder-commit/folder-commit-service";
|
import { TFolderCommitServiceFactory } from "../folder-commit/folder-commit-service";
|
||||||
import { TKmsServiceFactory } from "../kms/kms-service";
|
import { TKmsServiceFactory } from "../kms/kms-service";
|
||||||
|
import { TNotificationServiceFactory } from "../notification/notification-service";
|
||||||
|
import { NotificationType } from "../notification/notification-types";
|
||||||
import { TProjectDALFactory } from "../project/project-dal";
|
import { TProjectDALFactory } from "../project/project-dal";
|
||||||
import { TProjectServiceFactory } from "../project/project-service";
|
import { TProjectServiceFactory } from "../project/project-service";
|
||||||
import { TProjectEnvDALFactory } from "../project-env/project-env-dal";
|
import { TProjectEnvDALFactory } from "../project-env/project-env-dal";
|
||||||
@@ -42,6 +44,7 @@ export type TExternalMigrationQueueFactoryDep = {
|
|||||||
folderVersionDAL: Pick<TSecretFolderVersionDALFactory, "create">;
|
folderVersionDAL: Pick<TSecretFolderVersionDALFactory, "create">;
|
||||||
|
|
||||||
resourceMetadataDAL: Pick<TResourceMetadataDALFactory, "insertMany" | "delete">;
|
resourceMetadataDAL: Pick<TResourceMetadataDALFactory, "insertMany" | "delete">;
|
||||||
|
notificationService: Pick<TNotificationServiceFactory, "createUserNotifications">;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TExternalMigrationQueueFactory = ReturnType<typeof externalMigrationQueueFactory>;
|
export type TExternalMigrationQueueFactory = ReturnType<typeof externalMigrationQueueFactory>;
|
||||||
@@ -62,9 +65,12 @@ export const externalMigrationQueueFactory = ({
|
|||||||
folderDAL,
|
folderDAL,
|
||||||
folderCommitService,
|
folderCommitService,
|
||||||
folderVersionDAL,
|
folderVersionDAL,
|
||||||
resourceMetadataDAL
|
resourceMetadataDAL,
|
||||||
|
notificationService
|
||||||
}: TExternalMigrationQueueFactoryDep) => {
|
}: TExternalMigrationQueueFactoryDep) => {
|
||||||
const startImport = async (dto: {
|
const startImport = async (dto: {
|
||||||
|
orgId: string;
|
||||||
|
actorId: string;
|
||||||
actorEmail: string;
|
actorEmail: string;
|
||||||
importType: ExternalPlatforms;
|
importType: ExternalPlatforms;
|
||||||
data: {
|
data: {
|
||||||
@@ -87,9 +93,19 @@ export const externalMigrationQueueFactory = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
queueService.start(QueueName.ImportSecretsFromExternalSource, async (job) => {
|
queueService.start(QueueName.ImportSecretsFromExternalSource, async (job) => {
|
||||||
const { data, actorEmail, importType } = job.data;
|
const { data, actorEmail, importType, actorId, orgId } = job.data;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
await notificationService.createUserNotifications([
|
||||||
|
{
|
||||||
|
userId: actorId,
|
||||||
|
orgId,
|
||||||
|
type: NotificationType.IMPORT_STARTED,
|
||||||
|
title: "Import Started",
|
||||||
|
body: `An import from **${importType}** to Infisical has been started.`
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
await smtpService.sendMail({
|
await smtpService.sendMail({
|
||||||
recipients: [actorEmail],
|
recipients: [actorEmail],
|
||||||
subjectLine: "Infisical import started",
|
subjectLine: "Infisical import started",
|
||||||
@@ -137,6 +153,16 @@ export const externalMigrationQueueFactory = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await notificationService.createUserNotifications([
|
||||||
|
{
|
||||||
|
userId: actorId,
|
||||||
|
orgId,
|
||||||
|
type: NotificationType.IMPORT_SUCCESSFUL,
|
||||||
|
title: "Import Successful",
|
||||||
|
body: `An import from **${importType}** to Infisical has successfully completed.`
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
await smtpService.sendMail({
|
await smtpService.sendMail({
|
||||||
recipients: [actorEmail],
|
recipients: [actorEmail],
|
||||||
subjectLine: "Infisical import successful",
|
subjectLine: "Infisical import successful",
|
||||||
@@ -146,6 +172,17 @@ export const externalMigrationQueueFactory = ({
|
|||||||
template: SmtpTemplates.ExternalImportSuccessful
|
template: SmtpTemplates.ExternalImportSuccessful
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
await notificationService.createUserNotifications([
|
||||||
|
{
|
||||||
|
userId: actorId,
|
||||||
|
orgId,
|
||||||
|
type: NotificationType.IMPORT_FAILED,
|
||||||
|
title: "Import Failed",
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
||||||
|
body: `An import from **${importType}** to Infisical has failed: ${(err as any)?.message || "Unknown error"}.`
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
await smtpService.sendMail({
|
await smtpService.sendMail({
|
||||||
recipients: [job.data.actorEmail],
|
recipients: [job.data.actorEmail],
|
||||||
subjectLine: "Infisical import failed",
|
subjectLine: "Infisical import failed",
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ export const externalMigrationServiceFactory = ({
|
|||||||
const encrypted = crypto.encryption().symmetric().encryptWithRootEncryptionKey(stringifiedJson);
|
const encrypted = crypto.encryption().symmetric().encryptWithRootEncryptionKey(stringifiedJson);
|
||||||
|
|
||||||
await externalMigrationQueue.startImport({
|
await externalMigrationQueue.startImport({
|
||||||
|
actorId: user.id,
|
||||||
|
orgId: actorOrgId,
|
||||||
actorEmail: user.email!,
|
actorEmail: user.email!,
|
||||||
importType: ExternalPlatforms.EnvKey,
|
importType: ExternalPlatforms.EnvKey,
|
||||||
data: {
|
data: {
|
||||||
@@ -131,6 +133,8 @@ export const externalMigrationServiceFactory = ({
|
|||||||
const encrypted = crypto.encryption().symmetric().encryptWithRootEncryptionKey(stringifiedJson);
|
const encrypted = crypto.encryption().symmetric().encryptWithRootEncryptionKey(stringifiedJson);
|
||||||
|
|
||||||
await externalMigrationQueue.startImport({
|
await externalMigrationQueue.startImport({
|
||||||
|
actorId: user.id,
|
||||||
|
orgId: actorOrgId,
|
||||||
actorEmail: user.email!,
|
actorEmail: user.email!,
|
||||||
importType: ExternalPlatforms.Vault,
|
importType: ExternalPlatforms.Vault,
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ export enum NotificationType {
|
|||||||
SECRET_SCANNING_SECRETS_DETECTED = "secret-scanning-secrets-detected",
|
SECRET_SCANNING_SECRETS_DETECTED = "secret-scanning-secrets-detected",
|
||||||
SECRET_SCANNING_SCAN_FAILED = "secret-scanning-scan-failed",
|
SECRET_SCANNING_SCAN_FAILED = "secret-scanning-scan-failed",
|
||||||
LOGIN_FROM_NEW_DEVICE = "login-from-new-device",
|
LOGIN_FROM_NEW_DEVICE = "login-from-new-device",
|
||||||
ADMIN_SSO_BYPASS = "admin-sso-bypass"
|
ADMIN_SSO_BYPASS = "admin-sso-bypass",
|
||||||
|
IMPORT_STARTED = "import-started",
|
||||||
|
IMPORT_SUCCESSFUL = "import-successful",
|
||||||
|
IMPORT_FAILED = "import-failed"
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TCreateUserNotificationDTO {
|
export interface TCreateUserNotificationDTO {
|
||||||
|
|||||||
Reference in New Issue
Block a user