mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 21:40:31 +00:00
Rename pki alerting structures
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
export { useCreateAlert, useDeleteAlert,useUpdateAlert } from "./mutations";
|
||||
export { useGetAlertById } from "./queries";
|
||||
export { useCreatePkiAlert, useDeletePkiAlert, useUpdatePkiAlert } from "./mutations";
|
||||
export { useGetPkiAlertById } from "./queries";
|
||||
|
||||
@@ -6,7 +6,7 @@ import { workspaceKeys } from "../workspace/queries";
|
||||
import { pkiAlertKeys } from "./queries";
|
||||
import { TCreatePkiAlertDTO, TDeletePkiAlertDTO, TPkiAlert, TUpdatePkiAlertDTO } from "./types";
|
||||
|
||||
export const useCreateAlert = () => {
|
||||
export const useCreatePkiAlert = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TPkiAlert, {}, TCreatePkiAlertDTO>({
|
||||
mutationFn: async (body) => {
|
||||
@@ -19,7 +19,7 @@ export const useCreateAlert = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateAlert = () => {
|
||||
export const useUpdatePkiAlert = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TPkiAlert, {}, TUpdatePkiAlertDTO>({
|
||||
mutationFn: async ({ alertId, ...body }) => {
|
||||
@@ -36,7 +36,7 @@ export const useUpdateAlert = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteAlert = () => {
|
||||
export const useDeletePkiAlert = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TPkiAlert, {}, TDeletePkiAlertDTO>({
|
||||
mutationFn: async ({ alertId }) => {
|
||||
|
||||
@@ -8,7 +8,7 @@ export const pkiAlertKeys = {
|
||||
getPkiAlertById: (alertId: string) => [{ alertId }, "alert"]
|
||||
};
|
||||
|
||||
export const useGetAlertById = (alertId: string) => {
|
||||
export const useGetPkiAlertById = (alertId: string) => {
|
||||
return useQuery({
|
||||
queryKey: pkiAlertKeys.getPkiAlertById(alertId),
|
||||
queryFn: async () => {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export enum PkiItemType {
|
||||
CERTIFICATE = "certificate",
|
||||
CA = "ca"
|
||||
}
|
||||
|
||||
export const pkiItemTypeToNameMap: { [K in PkiItemType]: string } = {
|
||||
[PkiItemType.CA]: "CA",
|
||||
[PkiItemType.CERTIFICATE]: "Certificate"
|
||||
};
|
||||
@@ -1,5 +1,7 @@
|
||||
export {
|
||||
useAddItemToPkiCollection,
|
||||
useCreatePkiCollection,
|
||||
useDeletePkiCollection,
|
||||
useRemoveItemFromPkiCollection,
|
||||
useUpdatePkiCollection} from "./mutations";
|
||||
export { useGetPkiCollectionById } from "./queries";
|
||||
export { useGetPkiCollectionById, useListPkiCollectionItems } from "./queries";
|
||||
|
||||
@@ -3,13 +3,14 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
// import { alertKeys } from "./queries";
|
||||
// import { TAlert, TCreateAlertDTO, TDeleteAlertDTO, TUpdateAlertDTO } from "./types";
|
||||
import { pkiCollectionKeys } from "./queries";
|
||||
import {
|
||||
TAddItemToPkiCollectionDTO,
|
||||
TCreatePkiCollectionDTO,
|
||||
TDeletePkiCollectionDTO,
|
||||
TPkiCollection,
|
||||
TPkiCollectionItem,
|
||||
TRemoveItemFromPkiCollectionDTO,
|
||||
TUpdatePkiCollectionTO} from "./types";
|
||||
|
||||
export const useCreatePkiCollection = () => {
|
||||
@@ -61,4 +62,36 @@ export const useDeletePkiCollection = () => {
|
||||
});
|
||||
};
|
||||
|
||||
// TODO: add PKI Collection Item
|
||||
export const useAddItemToPkiCollection = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TPkiCollectionItem, {}, TAddItemToPkiCollectionDTO>({
|
||||
mutationFn: async ({ collectionId, type, itemId }) => {
|
||||
const { data: pkiCollectionItem } = await apiRequest.post<TPkiCollectionItem>(
|
||||
`/api/v1/pki/collections/${collectionId}/items`,
|
||||
{
|
||||
type,
|
||||
itemId
|
||||
}
|
||||
);
|
||||
return pkiCollectionItem;
|
||||
},
|
||||
onSuccess: (_, { collectionId }) => {
|
||||
queryClient.invalidateQueries(pkiCollectionKeys.getPkiCollectionItems(collectionId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useRemoveItemFromPkiCollection = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TPkiCollectionItem, {}, TRemoveItemFromPkiCollectionDTO>({
|
||||
mutationFn: async ({ collectionId, itemId }) => {
|
||||
const { data: pkiCollectionItem } = await apiRequest.delete<TPkiCollectionItem>(
|
||||
`/api/v1/pki/collections/${collectionId}/items/${itemId}`
|
||||
);
|
||||
return pkiCollectionItem;
|
||||
},
|
||||
onSuccess: (_, { collectionId }) => {
|
||||
queryClient.invalidateQueries(pkiCollectionKeys.getPkiCollectionItems(collectionId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -2,10 +2,26 @@ import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { TPkiCollection } from "./types";
|
||||
import { TPkiCollection, TPkiCollectionItem } from "./types";
|
||||
|
||||
export const pkiCollectionKeys = {
|
||||
getPkiCollectionById: (collectionId: string) => [{ collectionId }, "pki-collection"]
|
||||
getPkiCollectionById: (collectionId: string) => [{ collectionId }, "pki-collection"] as const,
|
||||
getPkiCollectionItems: (collectionId: string) =>
|
||||
[{ collectionId }, "pki-collection-items"] as const,
|
||||
specificPkiCollectionItems: ({
|
||||
collectionId,
|
||||
offset,
|
||||
limit
|
||||
}: {
|
||||
collectionId: string;
|
||||
offset: number;
|
||||
limit: number;
|
||||
}) =>
|
||||
[
|
||||
...pkiCollectionKeys.getPkiCollectionItems(collectionId),
|
||||
{ offset, limit },
|
||||
"pki-collection-items-2"
|
||||
] as const
|
||||
};
|
||||
|
||||
export const useGetPkiCollectionById = (collectionId: string) => {
|
||||
@@ -20,3 +36,39 @@ export const useGetPkiCollectionById = (collectionId: string) => {
|
||||
enabled: Boolean(collectionId)
|
||||
});
|
||||
};
|
||||
|
||||
export const useListPkiCollectionItems = ({
|
||||
collectionId,
|
||||
offset,
|
||||
limit
|
||||
}: {
|
||||
collectionId: string;
|
||||
offset: number;
|
||||
limit: number;
|
||||
}) => {
|
||||
return useQuery({
|
||||
queryKey: pkiCollectionKeys.specificPkiCollectionItems({
|
||||
collectionId,
|
||||
offset,
|
||||
limit
|
||||
}),
|
||||
queryFn: async () => {
|
||||
const params = new URLSearchParams({
|
||||
offset: String(offset),
|
||||
limit: String(limit)
|
||||
});
|
||||
|
||||
const {
|
||||
data: { collectionItems, totalCount }
|
||||
} = await apiRequest.get<{
|
||||
collectionItems: TPkiCollectionItem[];
|
||||
totalCount: number;
|
||||
}>(`/api/v1/pki/collections/${collectionId}/items`, {
|
||||
params
|
||||
});
|
||||
|
||||
return { collectionItems, totalCount };
|
||||
},
|
||||
enabled: Boolean(collectionId)
|
||||
});
|
||||
};
|
||||
|
||||
@@ -21,3 +21,23 @@ export type TDeletePkiCollectionDTO = {
|
||||
collectionId: string;
|
||||
projectId: string;
|
||||
};
|
||||
|
||||
export type TPkiCollectionItem = {
|
||||
id: string;
|
||||
collectionId: string;
|
||||
type: string;
|
||||
itemId: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type TAddItemToPkiCollectionDTO = {
|
||||
collectionId: string;
|
||||
type: string;
|
||||
itemId: string;
|
||||
};
|
||||
|
||||
export type TRemoveItemFromPkiCollectionDTO = {
|
||||
collectionId: string;
|
||||
itemId: string;
|
||||
};
|
||||
|
||||
@@ -23,10 +23,10 @@ export {
|
||||
useGetWorkspaceIntegrations,
|
||||
useGetWorkspaceSecrets,
|
||||
useGetWorkspaceUsers,
|
||||
useListWorkspaceAlerts,
|
||||
useListWorkspaceCas,
|
||||
useListWorkspaceCertificates,
|
||||
useListWorkspaceGroups,
|
||||
useListWorkspacePkiAlerts,
|
||||
useListWorkspacePkiCollections,
|
||||
useNameWorkspaceSecrets,
|
||||
useRenameWorkspace,
|
||||
|
||||
@@ -65,7 +65,8 @@ export const workspaceKeys = {
|
||||
offset: number;
|
||||
limit: number;
|
||||
}) => [...workspaceKeys.forWorkspaceCertificates(slug), { offset, limit }] as const,
|
||||
getWorkspacePkiAlerts: (workspaceId: string) => [{ workspaceId }, "workspace-alerts"] as const,
|
||||
getWorkspacePkiAlerts: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-pki-alerts"] as const,
|
||||
getWorkspacePkiCollections: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-pki-collections"] as const
|
||||
};
|
||||
@@ -607,7 +608,7 @@ export const useListWorkspaceCertificates = ({
|
||||
});
|
||||
};
|
||||
|
||||
export const useListWorkspaceAlerts = ({ workspaceId }: { workspaceId: string }) => {
|
||||
export const useListWorkspacePkiAlerts = ({ workspaceId }: { workspaceId: string }) => {
|
||||
return useQuery({
|
||||
queryKey: workspaceKeys.getWorkspacePkiAlerts(workspaceId),
|
||||
queryFn: async () => {
|
||||
|
||||
Reference in New Issue
Block a user