mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 11:38:55 +00:00
feat: HSM support
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
export {
|
||||
useAdminDeleteUser,
|
||||
useCreateAdminUser,
|
||||
useExportServerDecryptionKey,
|
||||
useImportServerDecryptionKey,
|
||||
useUpdateAdminSlackConfig,
|
||||
useUpdateServerConfig
|
||||
useUpdateServerConfig,
|
||||
useUpdateServerEncryptionStrategy
|
||||
} from "./mutation";
|
||||
export { useAdminGetUsers, useGetAdminSlackConfig, useGetServerConfig } from "./queries";
|
||||
export {
|
||||
useAdminGetUsers,
|
||||
useGetAdminSlackConfig,
|
||||
useGetServerConfig,
|
||||
useGetServerRootKmsEncryptionDetails
|
||||
} from "./queries";
|
||||
|
||||
@@ -7,6 +7,7 @@ import { User } from "../users/types";
|
||||
import { adminQueryKeys, adminStandaloneKeys } from "./queries";
|
||||
import {
|
||||
AdminSlackConfig,
|
||||
RootKeyEncryptionStrategy,
|
||||
TCreateAdminUserDTO,
|
||||
TServerConfig,
|
||||
TUpdateAdminSlackConfigDTO
|
||||
@@ -85,3 +86,36 @@ export const useUpdateAdminSlackConfig = () => {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateServerEncryptionStrategy = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (strategy: RootKeyEncryptionStrategy) => {
|
||||
await apiRequest.post("/api/v1/admin/encryption-strategies", { strategy });
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(adminQueryKeys.getServerEncryptionStrategies());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useExportServerDecryptionKey = () => {
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
const { data } = await apiRequest.post<{ secretParts: string[] }>("/api/v1/admin/kms-export");
|
||||
return data.secretParts;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useImportServerDecryptionKey = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (secretParts: string[]) => {
|
||||
await apiRequest.post("/api/v1/admin/kms-import", { secretParts });
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(adminQueryKeys.serverConfig());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -3,7 +3,12 @@ import { useInfiniteQuery, useQuery, UseQueryOptions } from "@tanstack/react-que
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { User } from "../types";
|
||||
import { AdminGetUsersFilters, AdminSlackConfig, TServerConfig } from "./types";
|
||||
import {
|
||||
AdminGetUsersFilters,
|
||||
AdminSlackConfig,
|
||||
TGetServerRootKmsEncryptionDetails,
|
||||
TServerConfig
|
||||
} from "./types";
|
||||
|
||||
export const adminStandaloneKeys = {
|
||||
getUsers: "get-users"
|
||||
@@ -12,7 +17,8 @@ export const adminStandaloneKeys = {
|
||||
export const adminQueryKeys = {
|
||||
serverConfig: () => ["server-config"] as const,
|
||||
getUsers: (filters: AdminGetUsersFilters) => [adminStandaloneKeys.getUsers, { filters }] as const,
|
||||
getAdminSlackConfig: () => ["admin-slack-config"] as const
|
||||
getAdminSlackConfig: () => ["admin-slack-config"] as const,
|
||||
getServerEncryptionStrategies: () => ["server-encryption-strategies"] as const
|
||||
};
|
||||
|
||||
const fetchServerConfig = async () => {
|
||||
@@ -61,8 +67,8 @@ export const useAdminGetUsers = (filters: AdminGetUsersFilters) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetAdminSlackConfig = () =>
|
||||
useQuery({
|
||||
export const useGetAdminSlackConfig = () => {
|
||||
return useQuery({
|
||||
queryKey: adminQueryKeys.getAdminSlackConfig(),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<AdminSlackConfig>(
|
||||
@@ -72,3 +78,17 @@ export const useGetAdminSlackConfig = () =>
|
||||
return data;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetServerRootKmsEncryptionDetails = () => {
|
||||
return useQuery({
|
||||
queryKey: adminQueryKeys.getServerEncryptionStrategies(),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TGetServerRootKmsEncryptionDetails>(
|
||||
"/api/v1/admin/root-kms-config"
|
||||
);
|
||||
|
||||
return data;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -54,3 +54,17 @@ export type AdminSlackConfig = {
|
||||
clientId: string;
|
||||
clientSecret: string;
|
||||
};
|
||||
|
||||
export type TGetServerRootKmsEncryptionDetails = {
|
||||
strategies: {
|
||||
strategy: RootKeyEncryptionStrategy;
|
||||
enabled: boolean;
|
||||
name: string;
|
||||
}[];
|
||||
keyExported: boolean;
|
||||
};
|
||||
|
||||
export enum RootKeyEncryptionStrategy {
|
||||
Basic = "BASIC",
|
||||
Hsm = "HSM"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { useCallback } from "react";
|
||||
|
||||
export const useFileDownload = () => {
|
||||
return useCallback((content: string, filename: string) => {
|
||||
const downloadUrl = `data:text/plain;charset=utf-8,${encodeURIComponent(content)}`;
|
||||
const link = document.createElement("a");
|
||||
link.href = downloadUrl;
|
||||
link.setAttribute("download", filename);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
}, []);
|
||||
};
|
||||
Reference in New Issue
Block a user