mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 18:15:53 +00:00
feat: completed KMIP client overview
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
export * from "./mutation";
|
||||
export * from "./queries";
|
||||
@@ -0,0 +1,58 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { kmipKeys } from "./queries";
|
||||
import { TCreateKmipClient, TDeleteKmipClient, TUpdateKmipClient } from "./types";
|
||||
|
||||
export const useCreateKmipClient = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (payload: TCreateKmipClient) => {
|
||||
const { data } = await apiRequest.post("/api/v1/kmip/clients", payload);
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { projectId }) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: kmipKeys.getKmipClientsByProjectId({ projectId })
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateKmipClient = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ id, name, description, permissions }: TUpdateKmipClient) => {
|
||||
const { data } = await apiRequest.patch(`/api/v1/kmip/clients/${id}`, {
|
||||
name,
|
||||
description,
|
||||
permissions
|
||||
});
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { projectId }) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: kmipKeys.getKmipClientsByProjectId({ projectId })
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteKmipClients = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ id }: TDeleteKmipClient) => {
|
||||
const { data } = await apiRequest.delete(`/api/v1/kmip/clients/${id}`);
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { projectId }) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: kmipKeys.getKmipClientsByProjectId({ projectId })
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,52 @@
|
||||
import { useQuery, UseQueryOptions } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { OrderByDirection } from "../generic/types";
|
||||
import { KmipClientOrderBy, TListProjectKmipClientsDTO, TProjectKmipClientList } from "./types";
|
||||
|
||||
export const kmipKeys = {
|
||||
getKmipClientsByProjectId: ({ projectId, ...filters }: TListProjectKmipClientsDTO) =>
|
||||
[projectId, filters] as const
|
||||
};
|
||||
|
||||
export const useGetKmipClientsByProjectId = (
|
||||
{
|
||||
projectId,
|
||||
offset = 0,
|
||||
limit = 100,
|
||||
orderBy = KmipClientOrderBy.Name,
|
||||
orderDirection = OrderByDirection.ASC,
|
||||
search = ""
|
||||
}: TListProjectKmipClientsDTO,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
TProjectKmipClientList,
|
||||
unknown,
|
||||
TProjectKmipClientList,
|
||||
ReturnType<typeof kmipKeys.getKmipClientsByProjectId>
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: kmipKeys.getKmipClientsByProjectId({
|
||||
projectId,
|
||||
offset,
|
||||
limit,
|
||||
orderBy,
|
||||
orderDirection,
|
||||
search
|
||||
}),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TProjectKmipClientList>("/api/v1/kmip/clients", {
|
||||
params: { projectId, offset, limit, search, orderBy, orderDirection }
|
||||
});
|
||||
|
||||
return data;
|
||||
},
|
||||
enabled: Boolean(projectId) && (options?.enabled ?? true),
|
||||
placeholderData: (previousData) => previousData,
|
||||
...options
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
import { OrderByDirection } from "../generic/types";
|
||||
|
||||
export enum KmipPermission {
|
||||
Create = "create",
|
||||
Locate = "locate",
|
||||
Check = "check",
|
||||
Get = "get"
|
||||
}
|
||||
|
||||
export type TKmipClient = {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
permissions: KmipPermission[];
|
||||
projectId: string;
|
||||
};
|
||||
|
||||
type ProjectRef = { projectId: string };
|
||||
type KeyRef = { id: string };
|
||||
|
||||
export type TCreateKmipClient = Pick<TKmipClient, "name" | "description" | "permissions"> &
|
||||
ProjectRef;
|
||||
|
||||
export type TUpdateKmipClient = KeyRef &
|
||||
Partial<Pick<TKmipClient, "name" | "description" | "permissions">> &
|
||||
ProjectRef;
|
||||
|
||||
export type TProjectKmipClientList = {
|
||||
kmipClients: TKmipClient[];
|
||||
totalCount: number;
|
||||
};
|
||||
|
||||
export type TDeleteKmipClient = KeyRef & ProjectRef;
|
||||
|
||||
export type TListProjectKmipClientsDTO = {
|
||||
projectId: string;
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
orderBy?: KmipClientOrderBy;
|
||||
orderDirection?: OrderByDirection;
|
||||
search?: string;
|
||||
};
|
||||
|
||||
export enum KmipClientOrderBy {
|
||||
Name = "name"
|
||||
}
|
||||
Reference in New Issue
Block a user