mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
Add React Query hooks for Hashicorp Vault config overrides
This commit is contained in:
parent
d8b367b4c7
commit
a21ed7528a
2 changed files with 44 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
import { getHashicorpVaultConfig } from "@/components/networking";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import useAuthorized from "../useAuthorized";
|
||||
import { createQueryKeys } from "../common/queryKeysFactory";
|
||||
|
||||
const hashicorpVaultKeys = createQueryKeys("hashicorpVaultConfig");
|
||||
|
||||
export const useHashicorpVaultConfig = () => {
|
||||
const { accessToken } = useAuthorized();
|
||||
|
||||
return useQuery<Record<string, any>>({
|
||||
queryKey: hashicorpVaultKeys.list({}),
|
||||
queryFn: async () => {
|
||||
if (!accessToken) {
|
||||
throw new Error("Access token is required");
|
||||
}
|
||||
return getHashicorpVaultConfig(accessToken);
|
||||
},
|
||||
enabled: !!accessToken,
|
||||
staleTime: 60 * 60 * 1000,
|
||||
gcTime: 60 * 60 * 1000,
|
||||
});
|
||||
};
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import { updateHashicorpVaultConfig } from "@/components/networking";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { createQueryKeys } from "../common/queryKeysFactory";
|
||||
|
||||
const hashicorpVaultKeys = createQueryKeys("hashicorpVaultConfig");
|
||||
|
||||
export const useUpdateHashicorpVaultConfig = (accessToken: string) => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (config: Record<string, any>) => {
|
||||
if (!accessToken) {
|
||||
throw new Error("Access token is required");
|
||||
}
|
||||
return updateHashicorpVaultConfig(accessToken, config);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: hashicorpVaultKeys.all });
|
||||
},
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue