From 0e4c3b5a7052b64d3213198edc9f10c6cc2bfa67 Mon Sep 17 00:00:00 2001 From: at2005 Date: Fri, 9 Aug 2024 15:45:06 +0000 Subject: [PATCH 1/2] change schema when making request --- src/lib/ssh.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/lib/ssh.ts b/src/lib/ssh.ts index 3cf67e67..18d1cde7 100644 --- a/src/lib/ssh.ts +++ b/src/lib/ssh.ts @@ -16,7 +16,6 @@ async function readFileOrKey(keyOrFile: string): Promise { throw new Error("File not found"); } const file = await fileContent.text(); - if (!isPubkey(file)) { throw new Error("The file content does not look like a valid public key"); } @@ -49,7 +48,6 @@ export function registerSSH(program: Command) { if (options.add) { const key = await readFileOrKey(options.add); const credential = await postSSHKeys(key); - console.log("Added ssh key"); return; } @@ -83,17 +81,18 @@ export async function getSSHKeys() { export async function postSSHKeys(key: string) { const res = await fetch(await getApiUrl("credentials_create"), { method: "POST", - headers: await getAuthorizationHeader(), + headers: { + ...await getAuthorizationHeader(), + 'Content-Type': 'application/json', + }, body: JSON.stringify({ pubkey: key, - user: "sf", + username: "sf", }), }); if (!res.ok) { - console.error(await res.text()); throw new Error("Failed to add SSH key"); } - const data = await res.json(); return data as SSHCredential; -} +} \ No newline at end of file From 229b2d8be58a92d5680e9c1dc4982734b37c1b00 Mon Sep 17 00:00:00 2001 From: at2005 Date: Fri, 9 Aug 2024 15:48:14 +0000 Subject: [PATCH 2/2] fmt --- src/lib/ssh.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/ssh.ts b/src/lib/ssh.ts index 18d1cde7..37edae21 100644 --- a/src/lib/ssh.ts +++ b/src/lib/ssh.ts @@ -48,6 +48,7 @@ export function registerSSH(program: Command) { if (options.add) { const key = await readFileOrKey(options.add); const credential = await postSSHKeys(key); + console.log("Added ssh key"); return; } @@ -82,8 +83,8 @@ export async function postSSHKeys(key: string) { const res = await fetch(await getApiUrl("credentials_create"), { method: "POST", headers: { - ...await getAuthorizationHeader(), - 'Content-Type': 'application/json', + ...(await getAuthorizationHeader()), + "Content-Type": "application/json", }, body: JSON.stringify({ pubkey: key, @@ -91,8 +92,9 @@ export async function postSSHKeys(key: string) { }), }); if (!res.ok) { + console.error(await res.text()); throw new Error("Failed to add SSH key"); } const data = await res.json(); return data as SSHCredential; -} \ No newline at end of file +}