Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

refactor(alerts): name things for what they are in the reminder alert code

Calvinac3b2501e32e
diff --git a/backend/src/services/alert/alert-channel-service.ts b/backend/src/services/alert/alert-channel-service.ts
index 3ca7269e1b..a7b57a7933 100644
--- a/backend/src/services/alert/alert-channel-service.ts
+++ b/backend/src/services/alert/alert-channel-service.ts
@@ -311,9 +311,8 @@ export const alertChannelServiceFactory = ({
}
};
- // For callers that carry recipient lists from outside the alert module (eg reminder recipients that
- // were never pruned when someone left the project), where an out-of-scope id should be dropped
- // rather than fail the whole write.
+ // For callers that carry recipient lists in from outside the alert module, which can name someone who
+ // has since left the scope. An out-of-scope id is dropped rather than failing the whole write.
const filterRecipientsInScope = async (
scope: { orgId: string; projectId?: string | null },
recipients: TChannelRecipientInput[],
diff --git a/backend/src/services/alert/alert-dal.ts b/backend/src/services/alert/alert-dal.ts
index d579cc8249..9373075869 100644
--- a/backend/src/services/alert/alert-dal.ts
+++ b/backend/src/services/alert/alert-dal.ts
@@ -5,7 +5,8 @@ import { TableName, TAlerts } from "@app/db/schemas";
import { DatabaseError } from "@app/lib/errors";
import { ormify, selectAllTableCols, sqlNestRelationships } from "@app/lib/knex";
-import { AlertTriggerType } from "./alert-types";
+import { AlertChannelType } from "./alert-channel-types";
+import { AlertPrincipalType, AlertTriggerType } from "./alert-types";
export type TAlertDALFactory = ReturnType<typeof alertDALFactory>;
@@ -201,7 +202,12 @@ export const alertDALFactory = (db: TDbClient) => {
resourceIds,
channelType,
principalType
- }: { resourceType: string; resourceIds: string[]; channelType: string; principalType: string },
+ }: {
+ resourceType: string;
+ resourceIds: string[];
+ channelType: AlertChannelType;
+ principalType: AlertPrincipalType;
+ },
tx?: Knex
): Promise<{ resourceId: string; principalId: string }[]> => {
if (resourceIds.length === 0) return [];
diff --git a/backend/src/services/alert/alert-service.ts b/backend/src/services/alert/alert-service.ts
index fe0a61acc3..4f66ba13d3 100644
--- a/backend/src/services/alert/alert-service.ts
+++ b/backend/src/services/alert/alert-service.ts
@@ -38,6 +38,7 @@ import {
import {
AlertAuditAction,
AlertPermissionAction,
+ AlertPrincipalType,
AlertRunStatus,
AlertTelemetryAction,
IResourceAlertProvider,
@@ -831,7 +832,12 @@ export const alertServiceFactory = ({
) => alertDAL.findOrphanedResourceIds(input, tx);
const findRecipientsForResources = (
- input: { resourceType: string; resourceIds: string[]; channelType: string; principalType: string },
+ input: {
+ resourceType: string;
+ resourceIds: string[];
+ channelType: AlertChannelType;
+ principalType: AlertPrincipalType;
+ },
tx?: Knex
) => alertDAL.findRecipientsForResources(input, tx);
diff --git a/backend/src/services/alert/providers/secret-reminder-alert-dal.ts b/backend/src/services/alert/providers/secret-reminder-alert-dal.ts
index 0ac15ab0f0..34a214c579 100644
--- a/backend/src/services/alert/providers/secret-reminder-alert-dal.ts
+++ b/backend/src/services/alert/providers/secret-reminder-alert-dal.ts
@@ -2,7 +2,7 @@ import { TDbClient } from "@app/db";
import { TableName } from "@app/db/schemas";
import { DatabaseError } from "@app/lib/errors";
-export type TReminderSecret = {
+export type TSecretWithLocation = {
secretId: string;
secretKey: string;
secretType: string;
@@ -19,7 +19,7 @@ export type TSecretReminderAlertDALFactory = ReturnType<typeof secretReminderAle
export const secretReminderAlertDALFactory = (db: TDbClient) => {
// Reads the primary: the event path treats an empty result as terminal, and a reminder can fire in
// the same run that the secret was written.
- const findReminderSecrets = async (secretIds: string[]): Promise<TReminderSecret[]> => {
+ const findSecretsByIds = async (secretIds: string[]): Promise<TSecretWithLocation[]> => {
if (secretIds.length === 0) return [];
try {
const rows = (await db(TableName.SecretV2)
@@ -38,7 +38,7 @@ export const secretReminderAlertDALFactory = (db: TDbClient) => {
db.ref("name").withSchema(TableName.Environment).as("envName"),
db.ref("id").withSchema(TableName.Project).as("projectId"),
db.ref("orgId").withSchema(TableName.Project).as("orgId")
- )) as Omit<TReminderSecret, "tagSlugs">[];
+ )) as Omit<TSecretWithLocation, "tagSlugs">[];
if (rows.length === 0) return [];
const tags = (await db(TableName.SecretV2JnTag)
@@ -57,9 +57,9 @@ export const secretReminderAlertDALFactory = (db: TDbClient) => {
tagSlugs: tags.filter((tag) => tag.secretId === row.secretId).map((tag) => tag.slug)
}));
} catch (error) {
- throw new DatabaseError({ error, name: "Find reminder secrets" });
+ throw new DatabaseError({ error, name: "FindSecretsByIds" });
}
};
- return { findReminderSecrets };
+ return { findSecretsByIds };
};
diff --git a/backend/src/services/alert/providers/secret-reminder-alert-provider.test.ts b/backend/src/services/alert/providers/secret-reminder-alert-provider.test.ts
index 0246ba3024..4f1de65483 100644
--- a/backend/src/services/alert/providers/secret-reminder-alert-provider.test.ts
+++ b/backend/src/services/alert/providers/secret-reminder-alert-provider.test.ts
@@ -8,14 +8,14 @@ import {
} from "@app/services/reminder/reminder-events";
import { AlertPermissionAction, TAlertContext } from "../alert-types";
-import { TReminderSecret } from "./secret-reminder-alert-dal";
+import { TSecretWithLocation } from "./secret-reminder-alert-dal";
import { secretReminderAlertProviderFactory } from "./secret-reminder-alert-provider";
vi.mock("@app/lib/config/env", () => ({
getConfig: () => ({ SITE_URL: "https://app.infisical.com" })
}));
-const SECRET: TReminderSecret = {
+const SECRET: TSecretWithLocation = {
secretId: "secret-1",
secretKey: "DB_PASSWORD",
secretType: "shared",
@@ -28,13 +28,17 @@ const SECRET: TReminderSecret = {
};
const buildProvider = (
- opts: { secrets?: TReminderSecret[]; rules?: { action: string; subject: string }[]; unresolvedPath?: boolean } = {}
+ opts: {
+ secrets?: TSecretWithLocation[];
+ rules?: { action: string; subject: string }[];
+ unresolvedPath?: boolean;
+ } = {}
) => {
const permissionCalls: unknown[] = [];
const pathLookupOptions: unknown[] = [];
const provider = secretReminderAlertProviderFactory({
secretReminderAlertDAL: {
- findReminderSecrets: async (ids: string[]) =>
+ findSecretsByIds: async (ids: string[]) =>
(opts.secrets ?? [SECRET]).filter((secret) => ids.includes(secret.secretId))
},
folderDAL: {
diff --git a/backend/src/services/alert/providers/secret-reminder-alert-provider.ts b/backend/src/services/alert/providers/secret-reminder-alert-provider.ts
index 739e20d7ae..1b85630b08 100644
--- a/backend/src/services/alert/providers/secret-reminder-alert-provider.ts
+++ b/backend/src/services/alert/providers/secret-reminder-alert-provider.ts
@@ -23,11 +23,11 @@ import {
TAlertPermissionInput,
TFindEventTargetsInput
} from "../alert-types";
-import { TReminderSecret, TSecretReminderAlertDALFactory } from "./secret-reminder-alert-dal";
+import { TSecretReminderAlertDALFactory, TSecretWithLocation } from "./secret-reminder-alert-dal";
const SecretReminderConditionSchema = z.object({}).nullish();
-export type TSecretReminderTarget = TReminderSecret & {
+export type TSecretReminderTarget = TSecretWithLocation & {
secretPath: string;
note: string | null;
repeatDays: number | null;
@@ -35,7 +35,7 @@ export type TSecretReminderTarget = TReminderSecret & {
};
export type TSecretReminderAlertProviderDep = {
- secretReminderAlertDAL: Pick<TSecretReminderAlertDALFactory, "findReminderSecrets">;
+ secretReminderAlertDAL: Pick<TSecretReminderAlertDALFactory, "findSecretsByIds">;
folderDAL: Pick<TSecretFolderDALFactory, "findSecretPathByFolderIds">;
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
};
@@ -59,7 +59,7 @@ export const secretReminderAlertProviderFactory = ({
permissionService
}: TSecretReminderAlertProviderDep): IEventAlertProvider<TSecretReminderTarget> => {
const $loadSecretsWithPath = async (secretIds: string[]) => {
- const secrets = await secretReminderAlertDAL.findReminderSecrets(secretIds);
+ const secrets = await secretReminderAlertDAL.findSecretsByIds(secretIds);
const paths = new Map<string, string>();
const folderIdsByProject = new Map<string, string[]>();
secrets.forEach((secret) => {
diff --git a/backend/src/services/reminder/reminder-service.ts b/backend/src/services/reminder/reminder-service.ts
index 60afeaba1a..9b9c659680 100644
--- a/backend/src/services/reminder/reminder-service.ts
+++ b/backend/src/services/reminder/reminder-service.ts
@@ -323,7 +323,6 @@ export const reminderServiceFactory = ({
// to because alerts.resourceId has no foreign key.
const reapOrphanedReminderAlerts: TReminderServiceFactory["reapOrphanedReminderAlerts"] = async () => {
for (let batch = 0; batch < MAX_ORPHAN_REAP_BATCHES; batch += 1) {
- // eslint-disable-next-line no-await-in-loop -- each batch is its own short transaction
const orphanedSecretIds = await alertService.findOrphanedResourceIds({
resourceType: SECRET_REMINDER_RESOURCE_TYPE,
resourceTable: TableName.SecretV2,
@@ -331,7 +330,6 @@ export const reminderServiceFactory = ({
});
if (orphanedSecretIds.length === 0) return;
- // eslint-disable-next-line no-await-in-loop
await alertService.deleteAlertsForDeletedResources({
resourceType: SECRET_REMINDER_RESOURCE_TYPE,
resourceIds: orphanedSecretIds
diff --git a/frontend/src/hooks/api/alerts/queries.ts b/frontend/src/hooks/api/alerts/queries.ts
index 7cb530d573..663af0d037 100644
--- a/frontend/src/hooks/api/alerts/queries.ts
+++ b/frontend/src/hooks/api/alerts/queries.ts
@@ -9,7 +9,7 @@ export const alertKeys = {
list: (filters: TListAlertsDTO) => [...alertKeys.all, "list", filters] as const
};
-export const fetchAlerts = async (filters: TListAlertsDTO) => {
+const fetchAlerts = async (filters: TListAlertsDTO) => {
const { data } = await apiRequest.get<{ alerts: TAlert[] }>("/api/v1/alerts", {
params: filters
});