Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Add preview to revoke and renew alerts
Carlos Monastyrskice9cf23c02bc
diff --git a/backend/src/server/routes/v1/pki-alert-router.ts b/backend/src/server/routes/v1/pki-alert-router.tsindex f18728a23a..0a81c90ff1 100644--- a/backend/src/server/routes/v1/pki-alert-router.ts+++ b/backend/src/server/routes/v1/pki-alert-router.ts@@ -432,7 +432,8 @@ export const registerPkiAlertRouter = async (server: FastifyZodProvider) => {alertBefore: z.string().refine(createSecureAlertBeforeValidator(), "Must be in format like '30d', '1w', '3m', '1y'")- .describe("Alert timing (e.g., '30d', '1w')"),+ .describe("Alert timing (e.g., '30d', '1w'). Required for expiration previews, omit for other event types.")+ .optional(),limit: z.coerce.number().min(1).max(100).default(20),offset: z.coerce.number().min(0).default(0)}),diff --git a/backend/src/server/routes/v2/pki-alert-router.ts b/backend/src/server/routes/v2/pki-alert-router.tsindex 80e3d25375..1b10ad695d 100644--- a/backend/src/server/routes/v2/pki-alert-router.ts+++ b/backend/src/server/routes/v2/pki-alert-router.ts@@ -426,7 +426,8 @@ export const registerPkiAlertRouter = async (server: FastifyZodProvider) => {alertBefore: z.string().refine(createSecureAlertBeforeValidator(), "Must be in format like '30d', '1w', '3m', '1y'")- .describe("Alert timing (e.g., '30d', '1w')"),+ .describe("Alert timing (e.g., '30d', '1w'). Required for expiration previews, omit for other event types.")+ .optional(),limit: z.coerce.number().min(1).max(100).default(20),offset: z.coerce.number().min(0).default(0)}),diff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-service.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-service.tsindex 2f72cf1ef3..93bb9361ce 100644--- a/backend/src/services/pki-alert-v2/pki-alert-v2-service.ts+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-service.ts@@ -569,12 +569,6 @@ export const pkiAlertV2ServiceFactory = ({ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.PkiAlerts);- try {- parseTimeToPostgresInterval(alertBefore);- } catch (error) {- throw new BadRequestError({ message: "Invalid alertBefore format. Use format like '30d', '1w', '3m', '1y'" });- }-const options: {limit: number;offset: number;@@ -583,10 +577,19 @@ export const pkiAlertV2ServiceFactory = ({} = {limit,offset,- showPreview: true,- alertBefore: parseTimeToPostgresInterval(alertBefore)+ showPreview: true};+ if (alertBefore) {+ try {+ options.alertBefore = parseTimeToPostgresInterval(alertBefore);+ } catch (error) {+ throw new BadRequestError({+ message: "Invalid alertBefore format. Use format like '30d', '1w', '3m', '1y'"+ });+ }+ }+const result = await pkiAlertV2DAL.findMatchingCertificates(projectId, filters, options);return {diff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-types.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-types.tsindex e87e1c6791..497b5b3b5b 100644--- a/backend/src/services/pki-alert-v2/pki-alert-v2-types.ts+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-types.ts@@ -276,7 +276,7 @@ export type TListMatchingCertificatesDTO = TGenericPermission & {export type TListCurrentMatchingCertificatesDTO = TGenericPermission & {projectId: string;filters: TPkiFilters;- alertBefore: string;+ alertBefore?: string;limit?: number;offset?: number;};diff --git a/frontend/src/hooks/api/pkiAlertsV2/types.ts b/frontend/src/hooks/api/pkiAlertsV2/types.tsindex 47a154274c..8cbbd70aba 100644--- a/frontend/src/hooks/api/pkiAlertsV2/types.ts+++ b/frontend/src/hooks/api/pkiAlertsV2/types.ts@@ -176,7 +176,7 @@ export interface TGetPkiAlertV2MatchingCertificatesResponse {export interface TGetPkiAlertV2CurrentMatchingCertificates {projectId: string;filters: TPkiFilterRuleV2[];- alertBefore: string;+ alertBefore?: string;limit?: number;offset?: number;}diff --git a/frontend/src/views/PkiAlertsV2Page/components/CreatePkiAlertV2FormSteps.tsx b/frontend/src/views/PkiAlertsV2Page/components/CreatePkiAlertV2FormSteps.tsxindex 5a7191d575..053a3182ed 100644--- a/frontend/src/views/PkiAlertsV2Page/components/CreatePkiAlertV2FormSteps.tsx+++ b/frontend/src/views/PkiAlertsV2Page/components/CreatePkiAlertV2FormSteps.tsx@@ -131,17 +131,26 @@ export const CreatePkiAlertV2FormSteps = ({const watchedEventType = watch("eventType");const watchedAlertBefore = watch("alertBefore");+ const previewEnabledTypes = [+ PkiAlertEventTypeV2.EXPIRATION,+ PkiAlertEventTypeV2.RENEWAL,+ PkiAlertEventTypeV2.REVOCATION+ ];+ const isPreviewEnabled = !!currentProject?.id && previewEnabledTypes.includes(watchedEventType);+const { data: currentCertificatesData, isLoading: isLoadingCurrentCertificates } =useGetPkiAlertV2CurrentMatchingCertificates({projectId: currentProject?.id || "",filters: watchedFilters || [],- alertBefore: watchedAlertBefore || "30d",+ ...(watchedEventType === PkiAlertEventTypeV2.EXPIRATION+ ? { alertBefore: watchedAlertBefore || "30d" }+ : {}),limit: certificatesPerPage,offset: (certificatesPage - 1) * certificatesPerPage},{- enabled: !!currentProject?.id && watchedEventType === PkiAlertEventTypeV2.EXPIRATION,+ enabled: isPreviewEnabled,refetchOnWindowFocus: false});@@ -576,8 +585,12 @@ export const CreatePkiAlertV2FormSteps = ({<Tab.Panel><div className="space-y-6"><p className="mb-4 text-sm text-bunker-300">- Preview certificates that match your filter criteria. This helps verify your filters- are targeting the correct certificates.+ {watchedEventType === PkiAlertEventTypeV2.EXPIRATION &&+ "Preview certificates that will expire within the configured alert window and match your filter criteria."}+ {watchedEventType === PkiAlertEventTypeV2.RENEWAL &&+ "Preview active certificates that match your filter criteria. When any of these certificates are renewed, this alert will trigger."}+ {watchedEventType === PkiAlertEventTypeV2.REVOCATION &&+ "Preview active certificates that match your filter criteria. When any of these certificates are revoked, this alert will trigger."}</p><div className="space-y-4">@@ -592,18 +605,6 @@ export const CreatePkiAlertV2FormSteps = ({</THead><TBody>{(() => {- if (watchedEventType !== PkiAlertEventTypeV2.EXPIRATION) {- return (- <Tr>- <Td colSpan={3} className="py-8 text-center text-gray-400">- Certificate preview is available for expiration alerts. For other- alert types, notifications are triggered in real time when the event- occurs.- </Td>- </Tr>- );- }-if (isLoadingCurrentCertificates) {return Array.from({ length: 5 }, (_, index) => (<Tr key={`skeleton-row-${index}`}>diff --git a/frontend/src/views/PkiAlertsV2Page/components/CreatePkiAlertV2Modal.tsx b/frontend/src/views/PkiAlertsV2Page/components/CreatePkiAlertV2Modal.tsxindex c44e521a7b..f32a081a9e 100644--- a/frontend/src/views/PkiAlertsV2Page/components/CreatePkiAlertV2Modal.tsx+++ b/frontend/src/views/PkiAlertsV2Page/components/CreatePkiAlertV2Modal.tsx@@ -60,15 +60,24 @@ const TABS_WITHOUT_PREVIEW: TFormTab[] = [{ name: "Review", key: "review", fields: [] }];+const hasPreviewTab = (eventType?: PkiAlertEventTypeV2): boolean => {+ return (+ !eventType ||+ eventType === PkiAlertEventTypeV2.EXPIRATION ||+ eventType === PkiAlertEventTypeV2.RENEWAL ||+ eventType === PkiAlertEventTypeV2.REVOCATION+ );+};+const getFormTabs = (eventType?: PkiAlertEventTypeV2): TFormTab[] => {- if (eventType === PkiAlertEventTypeV2.EXPIRATION || !eventType) {+ if (hasPreviewTab(eventType)) {return TABS_WITH_PREVIEW;}return TABS_WITHOUT_PREVIEW;};const getChannelsTabIndex = (eventType?: PkiAlertEventTypeV2): number => {- return eventType === PkiAlertEventTypeV2.EXPIRATION || !eventType ? 3 : 2;+ return hasPreviewTab(eventType) ? 3 : 2;};export const CreatePkiAlertV2Modal = ({ isOpen, onOpenChange, alertToEdit, alertId }: Props) => {@@ -308,7 +317,7 @@ export const CreatePkiAlertV2Modal = ({ isOpen, onOpenChange, alertToEdit, alert<formclassName={twMerge("flex flex-col",- watchedEventType === PkiAlertEventTypeV2.EXPIRATION ? "min-h-[60vh]" : "min-h-[40vh]",+ hasPreviewTab(watchedEventType) ? "min-h-[60vh]" : "min-h-[40vh]",isFinalStep && "max-h-[70vh] overflow-y-auto")}>@@ -340,7 +349,7 @@ export const CreatePkiAlertV2Modal = ({ isOpen, onOpenChange, alertToEdit, alert<CreatePkiAlertV2FormStepsexpandedChannel={expandedChannel}setExpandedChannel={setExpandedChannel}- showPreview={watchedEventType === PkiAlertEventTypeV2.EXPIRATION}+ showPreview={hasPreviewTab(watchedEventType)}/></Tab.Panels></Tab.Group>