mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 04:26:43 +00:00
feat(notifications): secret rotation failed notification
This commit is contained in:
@@ -17,6 +17,8 @@ import {
|
|||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { logger } from "@app/lib/logger";
|
import { logger } from "@app/lib/logger";
|
||||||
import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
|
import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
|
||||||
|
import { TNotificationServiceFactory } from "@app/services/notification/notification-service";
|
||||||
|
import { NotificationType } from "@app/services/notification/notification-types";
|
||||||
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
||||||
import { TProjectMembershipDALFactory } from "@app/services/project-membership/project-membership-dal";
|
import { TProjectMembershipDALFactory } from "@app/services/project-membership/project-membership-dal";
|
||||||
import { SmtpTemplates, TSmtpService } from "@app/services/smtp/smtp-service";
|
import { SmtpTemplates, TSmtpService } from "@app/services/smtp/smtp-service";
|
||||||
@@ -28,6 +30,7 @@ type TSecretRotationV2QueueServiceFactoryDep = {
|
|||||||
smtpService: Pick<TSmtpService, "sendMail">;
|
smtpService: Pick<TSmtpService, "sendMail">;
|
||||||
projectMembershipDAL: Pick<TProjectMembershipDALFactory, "findAllProjectMembers">;
|
projectMembershipDAL: Pick<TProjectMembershipDALFactory, "findAllProjectMembers">;
|
||||||
projectDAL: Pick<TProjectDALFactory, "findById">;
|
projectDAL: Pick<TProjectDALFactory, "findById">;
|
||||||
|
notificationService: Pick<TNotificationServiceFactory, "createUserNotifications">;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const secretRotationV2QueueServiceFactory = async ({
|
export const secretRotationV2QueueServiceFactory = async ({
|
||||||
@@ -36,7 +39,8 @@ export const secretRotationV2QueueServiceFactory = async ({
|
|||||||
secretRotationV2Service,
|
secretRotationV2Service,
|
||||||
projectMembershipDAL,
|
projectMembershipDAL,
|
||||||
projectDAL,
|
projectDAL,
|
||||||
smtpService
|
smtpService,
|
||||||
|
notificationService
|
||||||
}: TSecretRotationV2QueueServiceFactoryDep) => {
|
}: TSecretRotationV2QueueServiceFactoryDep) => {
|
||||||
const appCfg = getConfig();
|
const appCfg = getConfig();
|
||||||
|
|
||||||
@@ -152,6 +156,19 @@ export const secretRotationV2QueueServiceFactory = async ({
|
|||||||
|
|
||||||
const rotationType = SECRET_ROTATION_NAME_MAP[type as SecretRotation];
|
const rotationType = SECRET_ROTATION_NAME_MAP[type as SecretRotation];
|
||||||
|
|
||||||
|
const rotationPath = `/projects/secret-management/${projectId}/secrets/${environment.slug}`;
|
||||||
|
|
||||||
|
await notificationService.createUserNotifications(
|
||||||
|
projectAdmins.map((admin) => ({
|
||||||
|
userId: admin.userId,
|
||||||
|
orgId: project.orgId,
|
||||||
|
type: NotificationType.SECRET_ROTATION_FAILED,
|
||||||
|
title: "Secret Rotation Failed",
|
||||||
|
body: `Your **${rotationType}** rotation **${rotationName}** failed to rotate.`,
|
||||||
|
link: rotationPath
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
await smtpService.sendMail({
|
await smtpService.sendMail({
|
||||||
recipients: projectAdmins.map((member) => member.user.email!).filter(Boolean),
|
recipients: projectAdmins.map((member) => member.user.email!).filter(Boolean),
|
||||||
template: SmtpTemplates.SecretRotationFailed,
|
template: SmtpTemplates.SecretRotationFailed,
|
||||||
@@ -165,9 +182,7 @@ export const secretRotationV2QueueServiceFactory = async ({
|
|||||||
secretPath: folder.path,
|
secretPath: folder.path,
|
||||||
environment: environment.name,
|
environment: environment.name,
|
||||||
projectName: project.name,
|
projectName: project.name,
|
||||||
rotationUrl: encodeURI(
|
rotationUrl: encodeURI(`${appCfg.SITE_URL}${rotationPath}`)
|
||||||
`${appCfg.SITE_URL}/projects/secret-management/${projectId}/secrets/${environment.slug}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -2017,7 +2017,8 @@ export const registerRoutes = async (
|
|||||||
queueService,
|
queueService,
|
||||||
projectDAL,
|
projectDAL,
|
||||||
projectMembershipDAL,
|
projectMembershipDAL,
|
||||||
smtpService
|
smtpService,
|
||||||
|
notificationService
|
||||||
});
|
});
|
||||||
|
|
||||||
const secretScanningV2Queue = await secretScanningV2QueueServiceFactory({
|
const secretScanningV2Queue = await secretScanningV2QueueServiceFactory({
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ export enum NotificationType {
|
|||||||
ACCESS_APPROVAL_REQUEST_UPDATED = "access-approval-request-updated",
|
ACCESS_APPROVAL_REQUEST_UPDATED = "access-approval-request-updated",
|
||||||
ACCESS_POLICY_BYPASSED = "access-policy-bypassed",
|
ACCESS_POLICY_BYPASSED = "access-policy-bypassed",
|
||||||
SECRET_CHANGE_REQUEST = "secret-change-request",
|
SECRET_CHANGE_REQUEST = "secret-change-request",
|
||||||
SECRET_CHANGE_POLICY_BYPASSED = "secret-change-policy-bypassed"
|
SECRET_CHANGE_POLICY_BYPASSED = "secret-change-policy-bypassed",
|
||||||
|
SECRET_ROTATION_FAILED = "secret-rotation-failed"
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TCreateUserNotificationDTO {
|
export interface TCreateUserNotificationDTO {
|
||||||
|
|||||||
Reference in New Issue
Block a user