feat: ssh keys filesystel

This commit is contained in:
Lorenzo Migliorero
2024-07-25 20:16:49 +02:00
parent d243470029
commit 1f81ebd4fe
6 changed files with 56 additions and 26 deletions

View File

@@ -6,6 +6,7 @@ import {
type apiUpdateSshKey,
sshKeys,
} from "@/server/db/schema";
import { removeSSHKey, saveSSHKey } from "@/server/utils/filesystem/ssh";
import { TRPCError } from "@trpc/server";
import { eq } from "drizzle-orm";
@@ -20,6 +21,11 @@ export const createSshKey = async ({
.returning()
.then((response) => response[0])
.catch((e) => console.error(e));
if (sshKey) {
saveSSHKey(sshKey.sshKeyId, sshKey.publicKey, privateKey);
}
if (!sshKey) {
throw new TRPCError({
code: "BAD_REQUEST",
@@ -38,6 +44,8 @@ export const removeSSHKeyById = async (
.where(eq(sshKeys.sshKeyId, sshKeyId))
.returning();
removeSSHKey(sshKeyId);
return result[0];
};