mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 03:26:27 +00:00
Improve deprecated certs invalidation logic
This commit is contained in:
@@ -51,11 +51,6 @@ export const DeletePkiSyncModal = ({ isOpen, onOpenChange, pkiSync, onComplete }
|
||||
title={`Are you sure you want to delete ${name}?`}
|
||||
deleteKey={name}
|
||||
onDeleteApproved={handleDeletePkiSync}
|
||||
>
|
||||
<p className="mt-4 text-sm text-bunker-300">
|
||||
This action will also remove all certificates that were synced by this configuration from
|
||||
the {PKI_SYNC_MAP[destination].name} destination.
|
||||
</p>
|
||||
</DeleteActionModal>
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ type ContentProps = {
|
||||
};
|
||||
|
||||
const Content = ({ pkiSync, onComplete }: ContentProps) => {
|
||||
const { id: syncId, destination } = pkiSync;
|
||||
const { id: syncId, destination, projectId } = pkiSync;
|
||||
const destinationName = PKI_SYNC_MAP[destination].name;
|
||||
|
||||
const triggerImportCertificates = useTriggerPkiSyncImportCertificates();
|
||||
@@ -24,7 +24,8 @@ const Content = ({ pkiSync, onComplete }: ContentProps) => {
|
||||
try {
|
||||
await triggerImportCertificates.mutateAsync({
|
||||
syncId,
|
||||
destination
|
||||
destination,
|
||||
projectId
|
||||
});
|
||||
|
||||
createNotification({
|
||||
|
||||
@@ -15,7 +15,7 @@ type ContentProps = {
|
||||
};
|
||||
|
||||
const Content = ({ pkiSync, onComplete }: ContentProps) => {
|
||||
const { id: syncId, destination } = pkiSync;
|
||||
const { id: syncId, destination, projectId } = pkiSync;
|
||||
const destinationName = PKI_SYNC_MAP[destination].name;
|
||||
|
||||
const triggerRemoveCertificates = useTriggerPkiSyncRemoveCertificates();
|
||||
@@ -24,7 +24,8 @@ const Content = ({ pkiSync, onComplete }: ContentProps) => {
|
||||
try {
|
||||
await triggerRemoveCertificates.mutateAsync({
|
||||
syncId,
|
||||
destination
|
||||
destination,
|
||||
projectId
|
||||
});
|
||||
|
||||
createNotification({
|
||||
|
||||
@@ -67,9 +67,6 @@ export const PkiSyncReviewFields = () => {
|
||||
{isAutoSyncEnabled ? "Enabled" : "Disabled"}
|
||||
</Badge>
|
||||
</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Upload Certificates">
|
||||
<Badge variant="success">Always Enabled</Badge>
|
||||
</GenericFieldLabel>
|
||||
{/* Hidden for now - Import certificates functionality disabled
|
||||
{syncOptions?.canImportCertificates !== undefined && (
|
||||
<GenericFieldLabel label="Import Certificates">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
import { PkiSyncStatus } from "@app/hooks/api/pkiSyncs/enums";
|
||||
import { pkiSyncKeys } from "@app/hooks/api/pkiSyncs/queries";
|
||||
import {
|
||||
TCreatePkiSyncDTO,
|
||||
@@ -69,10 +70,39 @@ export const useTriggerPkiSyncSyncCertificates = () => {
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { syncId }) => {
|
||||
// Invalidate all PKI sync queries since we don't have projectId here
|
||||
queryClient.invalidateQueries({ queryKey: pkiSyncKeys.all });
|
||||
queryClient.invalidateQueries({ queryKey: ["pkiSync", syncId] });
|
||||
onMutate: async ({ syncId, projectId }) => {
|
||||
await queryClient.cancelQueries({ queryKey: pkiSyncKeys.byId(syncId, projectId) });
|
||||
await queryClient.cancelQueries({ queryKey: pkiSyncKeys.list(projectId) });
|
||||
|
||||
const previousPkiSync = queryClient.getQueryData(pkiSyncKeys.byId(syncId, projectId));
|
||||
|
||||
if (previousPkiSync) {
|
||||
queryClient.setQueryData(pkiSyncKeys.byId(syncId, projectId), {
|
||||
...previousPkiSync,
|
||||
syncStatus: PkiSyncStatus.Pending
|
||||
});
|
||||
}
|
||||
|
||||
return { previousPkiSync };
|
||||
},
|
||||
onSuccess: (_, { syncId, projectId }) => {
|
||||
const currentData = queryClient.getQueryData(pkiSyncKeys.byId(syncId, projectId));
|
||||
if (currentData) {
|
||||
queryClient.setQueryData(pkiSyncKeys.byId(syncId, projectId), {
|
||||
...currentData,
|
||||
syncStatus: PkiSyncStatus.Pending
|
||||
});
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
queryClient.invalidateQueries({ queryKey: pkiSyncKeys.byId(syncId, projectId) });
|
||||
queryClient.invalidateQueries({ queryKey: pkiSyncKeys.list(projectId) });
|
||||
}, 2000); // Wait 2 seconds before refetching
|
||||
},
|
||||
onError: (_, { syncId, projectId }, context) => {
|
||||
if (context?.previousPkiSync) {
|
||||
queryClient.setQueryData(pkiSyncKeys.byId(syncId, projectId), context.previousPkiSync);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -85,10 +115,39 @@ export const useTriggerPkiSyncImportCertificates = () => {
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { syncId }) => {
|
||||
// Invalidate all PKI sync queries since we don't have projectId here
|
||||
queryClient.invalidateQueries({ queryKey: pkiSyncKeys.all });
|
||||
queryClient.invalidateQueries({ queryKey: ["pkiSync", syncId] });
|
||||
onMutate: async ({ syncId, projectId }) => {
|
||||
await queryClient.cancelQueries({ queryKey: pkiSyncKeys.byId(syncId, projectId) });
|
||||
await queryClient.cancelQueries({ queryKey: pkiSyncKeys.list(projectId) });
|
||||
|
||||
const previousPkiSync = queryClient.getQueryData(pkiSyncKeys.byId(syncId, projectId));
|
||||
|
||||
if (previousPkiSync) {
|
||||
queryClient.setQueryData(pkiSyncKeys.byId(syncId, projectId), {
|
||||
...previousPkiSync,
|
||||
importStatus: PkiSyncStatus.Pending
|
||||
});
|
||||
}
|
||||
|
||||
return { previousPkiSync };
|
||||
},
|
||||
onSuccess: (_, { syncId, projectId }) => {
|
||||
const currentData = queryClient.getQueryData(pkiSyncKeys.byId(syncId, projectId));
|
||||
if (currentData) {
|
||||
queryClient.setQueryData(pkiSyncKeys.byId(syncId, projectId), {
|
||||
...currentData,
|
||||
importStatus: PkiSyncStatus.Pending
|
||||
});
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
queryClient.invalidateQueries({ queryKey: pkiSyncKeys.byId(syncId, projectId) });
|
||||
queryClient.invalidateQueries({ queryKey: pkiSyncKeys.list(projectId) });
|
||||
}, 2000); // Wait 2 seconds before refetching
|
||||
},
|
||||
onError: (_, { syncId, projectId }, context) => {
|
||||
if (context?.previousPkiSync) {
|
||||
queryClient.setQueryData(pkiSyncKeys.byId(syncId, projectId), context.previousPkiSync);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -103,10 +162,39 @@ export const useTriggerPkiSyncRemoveCertificates = () => {
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { syncId }) => {
|
||||
// Invalidate all PKI sync queries since we don't have projectId here
|
||||
queryClient.invalidateQueries({ queryKey: pkiSyncKeys.all });
|
||||
queryClient.invalidateQueries({ queryKey: ["pkiSync", syncId] });
|
||||
onMutate: async ({ syncId, projectId }) => {
|
||||
await queryClient.cancelQueries({ queryKey: pkiSyncKeys.byId(syncId, projectId) });
|
||||
await queryClient.cancelQueries({ queryKey: pkiSyncKeys.list(projectId) });
|
||||
|
||||
const previousPkiSync = queryClient.getQueryData(pkiSyncKeys.byId(syncId, projectId));
|
||||
|
||||
if (previousPkiSync) {
|
||||
queryClient.setQueryData(pkiSyncKeys.byId(syncId, projectId), {
|
||||
...previousPkiSync,
|
||||
removeStatus: PkiSyncStatus.Pending
|
||||
});
|
||||
}
|
||||
|
||||
return { previousPkiSync };
|
||||
},
|
||||
onSuccess: (_, { syncId, projectId }) => {
|
||||
const currentData = queryClient.getQueryData(pkiSyncKeys.byId(syncId, projectId));
|
||||
if (currentData) {
|
||||
queryClient.setQueryData(pkiSyncKeys.byId(syncId, projectId), {
|
||||
...currentData,
|
||||
removeStatus: PkiSyncStatus.Pending
|
||||
});
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
queryClient.invalidateQueries({ queryKey: pkiSyncKeys.byId(syncId, projectId) });
|
||||
queryClient.invalidateQueries({ queryKey: pkiSyncKeys.list(projectId) });
|
||||
}, 2000); // Wait 2 seconds before refetching
|
||||
},
|
||||
onError: (_, { syncId, projectId }, context) => {
|
||||
if (context?.previousPkiSync) {
|
||||
queryClient.setQueryData(pkiSyncKeys.byId(syncId, projectId), context.previousPkiSync);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -48,16 +48,19 @@ export type TDeletePkiSyncDTO = {
|
||||
export type TTriggerPkiSyncSyncCertificatesDTO = {
|
||||
syncId: string;
|
||||
destination: PkiSync;
|
||||
projectId: string;
|
||||
};
|
||||
|
||||
export type TTriggerPkiSyncImportCertificatesDTO = {
|
||||
syncId: string;
|
||||
destination: PkiSync;
|
||||
projectId: string;
|
||||
};
|
||||
|
||||
export type TTriggerPkiSyncRemoveCertificatesDTO = {
|
||||
syncId: string;
|
||||
destination: PkiSync;
|
||||
projectId: string;
|
||||
};
|
||||
|
||||
export * from "./common";
|
||||
|
||||
+1
-1
@@ -164,7 +164,7 @@ export const PkiSyncRow = ({
|
||||
</div>
|
||||
</Td>
|
||||
{subscriberId ? (
|
||||
<PkiSyncTableCell primaryText={subscriberId} secondaryText="PKI Subscriber" />
|
||||
<PkiSyncTableCell primaryText={pkiSync.subscriber?.name || subscriberId} secondaryText="PKI Subscriber" />
|
||||
) : (
|
||||
<Td>
|
||||
<Tooltip content="The PKI subscriber for this sync has been deleted. Configure a new source or remove this sync.">
|
||||
|
||||
+2
-1
@@ -252,7 +252,8 @@ export const PkiSyncsTable = ({ pkiSyncs }: Props) => {
|
||||
try {
|
||||
await triggerSync.mutateAsync({
|
||||
syncId: pkiSync.id,
|
||||
destination: pkiSync.destination
|
||||
destination: pkiSync.destination,
|
||||
projectId: pkiSync.projectId
|
||||
});
|
||||
|
||||
createNotification({
|
||||
|
||||
+4
-1
@@ -45,7 +45,10 @@ export const PkiSyncsTab = () => {
|
||||
}, [addSync, handlePopUpOpen, navigateToBase]);
|
||||
|
||||
const { data: pkiSyncs = [], isPending: isPkiSyncsPending } = useListPkiSyncs(
|
||||
currentProject?.id || ""
|
||||
currentProject?.id || "",
|
||||
{
|
||||
refetchInterval: 30000
|
||||
}
|
||||
);
|
||||
|
||||
if (isPkiSyncsPending)
|
||||
|
||||
+3
-2
@@ -89,7 +89,8 @@ export const PkiSyncActionTriggers = ({ pkiSync }: Props) => {
|
||||
try {
|
||||
await triggerSyncMutation.mutateAsync({
|
||||
syncId: id,
|
||||
destination
|
||||
destination,
|
||||
projectId
|
||||
});
|
||||
createNotification({
|
||||
text: "PKI sync job queued successfully",
|
||||
@@ -102,7 +103,7 @@ export const PkiSyncActionTriggers = ({ pkiSync }: Props) => {
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
}, [triggerSyncMutation, id, destination]);
|
||||
}, [triggerSyncMutation, id, destination, projectId]);
|
||||
|
||||
const handleToggleAutoSync = useCallback(async () => {
|
||||
try {
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ type Props = {
|
||||
};
|
||||
|
||||
export const PkiSyncSourceSection = ({ pkiSync, onEditSource }: Props) => {
|
||||
const { subscriberId } = pkiSync;
|
||||
const { subscriberId, subscriber } = pkiSync;
|
||||
|
||||
const permissionSubject = subject(ProjectPermissionSub.PkiSyncs, {
|
||||
subscriberId: subscriberId || ""
|
||||
@@ -65,7 +65,7 @@ export const PkiSyncSourceSection = ({ pkiSync, onEditSource }: Props) => {
|
||||
<div>
|
||||
<div className="space-y-3">
|
||||
<GenericFieldLabel label="PKI Subscriber">
|
||||
{subscriberId || "Deleted"}
|
||||
{subscriber ? subscriber.name : "Deleted"}
|
||||
</GenericFieldLabel>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user