From 2724336cad1509c212cc615394d2e4aa06234cbd Mon Sep 17 00:00:00 2001 From: Lorenzo Migliorero Date: Thu, 25 Jul 2024 23:32:52 +0200 Subject: [PATCH] feat: ssh key type and whitespaces --- .../settings/ssh-keys/add-ssh-key.tsx | 54 +++++++++++-------- .../settings/ssh-keys/update-ssh-key.tsx | 21 +++++++- server/api/routers/ssh-key.ts | 9 ++-- server/db/schema/ssh-key.ts | 4 +- server/db/validations/index.ts | 35 ++++++++---- server/utils/filesystem/ssh.ts | 20 +++---- 6 files changed, 94 insertions(+), 49 deletions(-) diff --git a/components/dashboard/settings/ssh-keys/add-ssh-key.tsx b/components/dashboard/settings/ssh-keys/add-ssh-key.tsx index cc6e03ab..903a8932 100644 --- a/components/dashboard/settings/ssh-keys/add-ssh-key.tsx +++ b/components/dashboard/settings/ssh-keys/add-ssh-key.tsx @@ -19,7 +19,7 @@ import { } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; -import { sshKeyCreate } from "@/server/db/validations"; +import { sshKeyCreate, type sshKeyType } from "@/server/db/validations"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; import { type ReactNode, useState } from "react"; @@ -65,6 +65,18 @@ export const AddSSHKey = ({ children }: Props) => { }); }; + const onGenerateSSHKey = (type: z.infer) => + generateMutation + .mutateAsync(type) + .then(async (data) => { + toast.success("SSH Key Generated"); + form.setValue("privateKey", data.privateKey); + form.setValue("publicKey", data.publicKey); + }) + .catch(() => { + toast.error("Error to generate the SSH Key"); + }); + return ( @@ -78,26 +90,26 @@ export const AddSSHKey = ({ children }: Props) => { In this section you can add one of your keys or generate a new one. - +
+ + +
{isError && {error?.message}} diff --git a/components/dashboard/settings/ssh-keys/update-ssh-key.tsx b/components/dashboard/settings/ssh-keys/update-ssh-key.tsx index 95f2ec1d..e763ee92 100644 --- a/components/dashboard/settings/ssh-keys/update-ssh-key.tsx +++ b/components/dashboard/settings/ssh-keys/update-ssh-key.tsx @@ -23,6 +23,8 @@ import { Textarea } from "@/components/ui/textarea"; import { sshKeyUpdate } from "@/server/db/validations"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; +import copy from "copy-to-clipboard"; +import { CopyIcon } from "lucide-react"; import { type ReactNode, useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; @@ -131,7 +133,24 @@ export const UpdateSSHKey = ({ children, sshKeyId = "" }: Props) => { Public Key -