feat: add ssh key

This commit is contained in:
Mauricio Siu
2024-10-02 22:50:01 -06:00
parent f13e5d449c
commit d41c8c70c3
24 changed files with 3908 additions and 192 deletions

View File

@@ -6,14 +6,10 @@ 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";
export const createSshKey = async ({
privateKey,
...input
}: typeof apiCreateSshKey._type) => {
export const createSshKey = async (input: typeof apiCreateSshKey._type) => {
await db.transaction(async (tx) => {
const sshKey = await tx
.insert(sshKeys)
@@ -22,10 +18,6 @@ export const createSshKey = async ({
.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",
@@ -44,8 +36,6 @@ export const removeSSHKeyById = async (
.where(eq(sshKeys.sshKeyId, sshKeyId))
.returning();
removeSSHKey(sshKeyId);
return result[0];
};