misc: partial project kms switch

This commit is contained in:
Sheen Capadngan
2024-07-30 23:03:52 +05:30
committed by =
parent cb347aa16a
commit 7e5c3e8163
9 changed files with 277 additions and 17 deletions
+7 -2
View File
@@ -1,2 +1,7 @@
export { useAddAwsExternalKms, useRemoveExternalKms, useUpdateAwsExternalKms } from "./mutations";
export { useGetExternalKmsById, useGetExternalKmsList } from "./queries";
export {
useAddAwsExternalKms,
useRemoveExternalKms,
useUpdateAwsExternalKms,
useUpdateProjectKms
} from "./mutations";
export { useGetActiveProjectKms, useGetExternalKmsById, useGetExternalKmsList } from "./queries";
+14
View File
@@ -126,3 +126,17 @@ export const useRemoveExternalKms = (orgId: string) => {
}
});
};
export const useUpdateProjectKms = (projectId: string) => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async (updatedData: { secretManagerKmsKeyId: string }) => {
const { data } = await apiRequest.patch(`/api/v1/workspace/${projectId}/kms`, updatedData);
return data;
},
onSuccess: () => {
queryClient.invalidateQueries(kmsKeys.getActiveProjectKms(projectId));
}
});
};
+21 -1
View File
@@ -6,7 +6,8 @@ import { Kms, KmsListEntry } from "./types";
export const kmsKeys = {
getExternalKmsList: (orgId: string) => ["get-all-external-kms", { orgId }],
getExternalKmsById: (id: string) => ["get-external-kms", { id }]
getExternalKmsById: (id: string) => ["get-external-kms", { id }],
getActiveProjectKms: (projectId: string) => ["get-active-project-kms", { projectId }]
};
export const useGetExternalKmsList = (orgId: string) => {
@@ -33,3 +34,22 @@ export const useGetExternalKmsById = (kmsId: string) => {
}
});
};
export const useGetActiveProjectKms = (projectId: string) => {
return useQuery({
queryKey: kmsKeys.getActiveProjectKms(projectId),
enabled: Boolean(projectId),
queryFn: async () => {
const {
data: { secretManagerKmsKey }
} = await apiRequest.get<{
secretManagerKmsKey: {
id: string;
slug: string;
isExternal: string;
};
}>(`/api/v1/workspace/${projectId}/kms`);
return secretManagerKmsKey;
}
});
};