mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 21:40:31 +00:00
feat: finalized kms settings in org-level
This commit is contained in:
@@ -1 +1,2 @@
|
||||
export { useAddAwsExternalKms } from "./mutations";
|
||||
export { useAddAwsExternalKms, useRemoveExternalKms, useUpdateAwsExternalKms } from "./mutations";
|
||||
export { useGetExternalKmsById, useGetExternalKmsList } from "./queries";
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
export const useAddAwsExternalKms = () => {
|
||||
import { kmsKeys } from "./queries";
|
||||
|
||||
export const useAddAwsExternalKms = (orgId: string) => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
slug,
|
||||
@@ -48,6 +51,78 @@ export const useAddAwsExternalKms = () => {
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess() {}
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(kmsKeys.getExternalKmsList(orgId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateAwsExternalKms = (orgId: string) => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
kmsId,
|
||||
slug,
|
||||
description,
|
||||
credentialType,
|
||||
accessKey,
|
||||
secretKey,
|
||||
assumeRoleArn,
|
||||
externalId,
|
||||
awsRegion,
|
||||
kmsKeyId
|
||||
}: {
|
||||
kmsId: string;
|
||||
slug?: string;
|
||||
description?: string;
|
||||
credentialType?: string;
|
||||
accessKey?: string;
|
||||
secretKey?: string;
|
||||
assumeRoleArn?: string;
|
||||
externalId?: string;
|
||||
awsRegion: string;
|
||||
kmsKeyId?: string;
|
||||
}) => {
|
||||
const { data } = await apiRequest.patch(`/api/v1/external-kms/${kmsId}`, {
|
||||
slug,
|
||||
description,
|
||||
provider: {
|
||||
type: "aws",
|
||||
inputs: {
|
||||
credential: {
|
||||
type: credentialType,
|
||||
data: {
|
||||
accessKey,
|
||||
secretKey,
|
||||
assumeRoleArn,
|
||||
externalId
|
||||
}
|
||||
},
|
||||
awsRegion,
|
||||
kmsKeyId
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { kmsId }) => {
|
||||
queryClient.invalidateQueries(kmsKeys.getExternalKmsList(orgId));
|
||||
queryClient.invalidateQueries(kmsKeys.getExternalKmsById(kmsId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useRemoveExternalKms = (orgId: string) => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (kmsId: string) => {
|
||||
const { data } = await apiRequest.delete(`/api/v1/external-kms/${kmsId}`);
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(kmsKeys.getExternalKmsList(orgId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { Kms, KmsListEntry } from "./types";
|
||||
|
||||
export const kmsKeys = {
|
||||
getExternalKmsList: (orgId: string) => ["get-all-external-kms", { orgId }],
|
||||
getExternalKmsById: (id: string) => ["get-external-kms", { id }]
|
||||
};
|
||||
|
||||
export const useGetExternalKmsList = (orgId: string) => {
|
||||
return useQuery({
|
||||
queryKey: kmsKeys.getExternalKmsList(orgId),
|
||||
queryFn: async () => {
|
||||
const {
|
||||
data: { externalKmsList }
|
||||
} = await apiRequest.get<{ externalKmsList: KmsListEntry[] }>("/api/v1/external-kms");
|
||||
return externalKmsList;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetExternalKmsById = (kmsId: string) => {
|
||||
return useQuery({
|
||||
queryKey: kmsKeys.getExternalKmsById(kmsId),
|
||||
enabled: Boolean(kmsId),
|
||||
queryFn: async () => {
|
||||
const {
|
||||
data: { externalKms }
|
||||
} = await apiRequest.get<{ externalKms: Kms }>(`/api/v1/external-kms/${kmsId}`);
|
||||
return externalKms;
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
export type Kms = {
|
||||
id: string;
|
||||
description: string;
|
||||
orgId: string;
|
||||
slug: string;
|
||||
external: {
|
||||
id: string;
|
||||
status: string;
|
||||
statusDetails: string;
|
||||
provider: string;
|
||||
providerInput: Record<string, any>;
|
||||
};
|
||||
};
|
||||
|
||||
export type KmsListEntry = {
|
||||
id: string;
|
||||
description: string;
|
||||
isDisabled: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
slug: string;
|
||||
externalKms: {
|
||||
provider: string;
|
||||
status: string;
|
||||
statusDetails: string;
|
||||
};
|
||||
};
|
||||
|
||||
export enum ExternalKmsProvider {
|
||||
AWS = "aws"
|
||||
}
|
||||
Reference in New Issue
Block a user