misc: addressed minor kms issues

This commit is contained in:
Sheen Capadngan
2024-07-24 23:45:38 +08:00
committed by =
parent 6a156371c0
commit 05d7e26f8b
4 changed files with 32 additions and 10 deletions

View File

@@ -69,7 +69,9 @@ export const useUpdateProjectKms = (projectId: string) => {
mutationFn: async (
updatedData: { type: KmsType.Internal } | { type: KmsType.External; kmsId: string }
) => {
const { data } = await apiRequest.patch(`/api/v1/workspace/${projectId}/kms`, updatedData);
const { data } = await apiRequest.patch(`/api/v1/workspace/${projectId}/kms`, {
kms: updatedData
});
return data;
},

View File

@@ -95,7 +95,7 @@ export const AddExternalKmsSchema = z.object({
.refine((v) => slugify(v) === v, {
message: "Alias must be a valid slug"
}),
description: z.string().trim().min(1).optional(),
description: z.string().trim().optional(),
provider: ExternalKmsInputSchema
});

View File

@@ -62,7 +62,7 @@ export const AwsKmsForm = ({ onCompleted, onCancel, kms }: Props) => {
resolver: zodResolver(AddExternalKmsSchema),
defaultValues: {
slug: kms?.slug,
description: kms?.description,
description: kms?.description ?? "",
provider: {
type: ExternalKmsProvider.AWS,
inputs: {

View File

@@ -23,7 +23,7 @@ import {
useOrganization,
useWorkspace
} from "@app/context";
import { usePopUp } from "@app/hooks";
import { usePopUp, useToggle } from "@app/hooks";
import {
useGetActiveProjectKms,
useGetExternalKmsList,
@@ -51,18 +51,36 @@ const BackupConfirmationModal = ({
org?: Organization;
workspace?: Workspace;
}) => {
const [isGeneratingBackup, setGeneratingBackup] = useToggle();
const downloadKmsBackup = async () => {
if (!workspace || !org) {
return;
}
const { secretManager } = await fetchProjectKmsBackup(workspace.id);
setGeneratingBackup.on();
const [, , kmsFunction] = secretManager.split(".");
const file = secretManager;
try {
const { secretManager } = await fetchProjectKmsBackup(workspace.id);
const blob = new Blob([file], { type: "text/plain;charset=utf-8" });
FileSaver.saveAs(blob, `kms-backup-${org.slug}-${workspace.slug}-${kmsFunction}.infisical.txt`);
const [, , kmsFunction] = secretManager.split(".");
const file = secretManager;
const blob = new Blob([file], { type: "text/plain;charset=utf-8" });
FileSaver.saveAs(
blob,
`kms-backup-${org.slug}-${workspace.slug}-${kmsFunction}.infisical.txt`
);
onOpenChange(false);
} catch (err) {
console.error(err);
createNotification({
text: "Failed to create KMS backup",
type: "error"
});
}
setGeneratingBackup.off();
};
return (
@@ -72,7 +90,9 @@ const BackupConfirmationModal = ({
In case of interruptions with your configured external KMS, you can load a backup to set
the project's KMS back to the default Infisical KMS.
</p>
<Button onClick={downloadKmsBackup}>Generate</Button>
<Button onClick={downloadKmsBackup} isLoading={isGeneratingBackup}>
Generate
</Button>
<Button
onClick={() => onOpenChange(false)}
colorSchema="secondary"