From ceda083776f7e14e4368d7ef0921bcf0d927701f Mon Sep 17 00:00:00 2001 From: Ved Prakash <54140516+thorved@users.noreply.github.com> Date: Wed, 8 Oct 2025 01:56:10 +0530 Subject: [PATCH 1/3] Refactor key_password to keyPassword for consistency across SSH routes --- src/backend/database/routes/ssh.ts | 25 ++++++++++++++++--------- src/backend/ssh/server-stats.ts | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/backend/database/routes/ssh.ts b/src/backend/database/routes/ssh.ts index 9304a647..94407726 100644 --- a/src/backend/database/routes/ssh.ts +++ b/src/backend/database/routes/ssh.ts @@ -91,7 +91,7 @@ router.get("/db/host/internal", async (req: Request, res: Response) => { username: host.username, password: host.autostartPassword, key: host.autostartKey, - key_password: host.autostartKeyPassword, + keyPassword: host.autostartKeyPassword, autostartPassword: host.autostartPassword, autostartKey: host.autostartKey, autostartKeyPassword: host.autostartKeyPassword, @@ -151,7 +151,7 @@ router.get("/db/host/internal/all", async (req: Request, res: Response) => { username: host.username, password: host.autostartPassword || host.password, key: host.autostartKey || host.key, - key_password: host.autostartKeyPassword || host.key_password, + keyPassword: host.autostartKeyPassword || host.key_password, autostartPassword: host.autostartPassword, autostartKey: host.autostartKey, autostartKeyPassword: host.autostartKeyPassword, @@ -226,7 +226,7 @@ router.post( authType, credentialId, key, - key_password, + keyPassword, keyType, pin, enableTerminal, @@ -278,7 +278,7 @@ router.post( sshDataObj.keyType = null; } else if (effectiveAuthType === "key") { sshDataObj.key = key || null; - sshDataObj.key_password = key_password || null; + sshDataObj.key_password = keyPassword || null; sshDataObj.keyType = keyType; sshDataObj.password = null; } else { @@ -407,7 +407,7 @@ router.put( authType, credentialId, key, - key_password, + keyPassword, keyType, pin, enableTerminal, @@ -464,8 +464,8 @@ router.put( if (key) { sshDataObj.key = key; } - if (key_password !== undefined) { - sshDataObj.key_password = key_password || null; + if (keyPassword !== undefined) { + sshDataObj.key_password = keyPassword || null; } if (keyType) { sshDataObj.keyType = keyType; @@ -1234,12 +1234,19 @@ async function resolveHostCredentials(host: any): Promise { authType: credential.auth_type || credential.authType, password: credential.password, key: credential.key, - key_password: credential.key_password || credential.key_password, + keyPassword: credential.key_password || credential.keyPassword, keyType: credential.key_type || credential.keyType, }; } } - return host; + + // Convert snake_case to camelCase for hosts without credentials + const result = { ...host }; + if (host.key_password !== undefined) { + result.keyPassword = host.key_password; + delete result.key_password; + } + return result; } catch (error) { sshLogger.warn( `Failed to resolve credentials for host ${host.id}: ${error instanceof Error ? error.message : "Unknown error"}`, diff --git a/src/backend/ssh/server-stats.ts b/src/backend/ssh/server-stats.ts index f580bb96..cc8c7e29 100644 --- a/src/backend/ssh/server-stats.ts +++ b/src/backend/ssh/server-stats.ts @@ -478,7 +478,7 @@ async function resolveHostCredentials( function addLegacyCredentials(baseHost: any, host: any): void { baseHost.password = host.password || null; baseHost.key = host.key || null; - baseHost.keyPassword = host.keyPassword || null; + baseHost.keyPassword = host.key_password || host.keyPassword || null; baseHost.keyType = host.keyType; } -- 2.49.1 From 51be6544cd310644cd69b8c1a70e6a2d3e5e1b89 Mon Sep 17 00:00:00 2001 From: Ved Prakash <54140516+thorved@users.noreply.github.com> Date: Wed, 8 Oct 2025 02:16:43 +0530 Subject: [PATCH 2/3] Standardizes keyPassword field handling and simplifies auth field logic Standardizes the handling of the `keyPassword` field by converting `key_password` to camelCase and ensuring consistent output while preserving resolved credentials. Removes redundant snake_case fields to avoid duplication. Simplifies UI handling of authentication fields by allowing non-relevant fields to persist, delegating filtering logic to the backend for cleaner and more maintainable code. Improves code clarity and aligns with consistent data handling practices. --- src/backend/database/routes/ssh.ts | 8 ++++++-- .../Apps/Host Manager/HostManagerEditor.tsx | 17 ++--------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/backend/database/routes/ssh.ts b/src/backend/database/routes/ssh.ts index 94407726..da00dfd7 100644 --- a/src/backend/database/routes/ssh.ts +++ b/src/backend/database/routes/ssh.ts @@ -711,7 +711,7 @@ router.get( authType: resolvedHost.authType, password: resolvedHost.password || null, key: resolvedHost.key || null, - key_password: resolvedHost.key_password || null, + keyPassword: resolvedHost.keyPassword || null, keyType: resolvedHost.keyType || null, folder: resolvedHost.folder, tags: @@ -1243,7 +1243,11 @@ async function resolveHostCredentials(host: any): Promise { // Convert snake_case to camelCase for hosts without credentials const result = { ...host }; if (host.key_password !== undefined) { - result.keyPassword = host.key_password; + // Only use the inline key_password if keyPassword hasn't been set by credential resolution + if (result.keyPassword === undefined) { + result.keyPassword = host.key_password; + } + // Always remove the snake_case version to standardize the output delete result.key_password; } return result; diff --git a/src/ui/Desktop/Apps/Host Manager/HostManagerEditor.tsx b/src/ui/Desktop/Apps/Host Manager/HostManagerEditor.tsx index fe0a2c0b..ad8e8d99 100644 --- a/src/ui/Desktop/Apps/Host Manager/HostManagerEditor.tsx +++ b/src/ui/Desktop/Apps/Host Manager/HostManagerEditor.tsx @@ -877,21 +877,8 @@ export function HostManagerEditor({ | "credential"; setAuthTab(newAuthType); form.setValue("authType", newAuthType); - - if (newAuthType === "password") { - form.setValue("key", null); - form.setValue("keyPassword", ""); - form.setValue("keyType", "auto"); - form.setValue("credentialId", null); - } else if (newAuthType === "key") { - form.setValue("password", ""); - form.setValue("credentialId", null); - } else if (newAuthType === "credential") { - form.setValue("password", ""); - form.setValue("key", null); - form.setValue("keyPassword", ""); - form.setValue("keyType", "auto"); - } + // Don't clear other auth fields - let them persist + // The backend will only use the fields relevant to the selected authType }} className="flex-1 flex flex-col h-full min-h-0" > -- 2.49.1 From 3e1388f0b34df79032e2f6eeb5a8e11ec1a5ea1d Mon Sep 17 00:00:00 2001 From: LukeGus Date: Tue, 7 Oct 2025 16:05:21 -0500 Subject: [PATCH 3/3] Cleanup code + resolve conversion logic --- src/backend/database/routes/ssh.ts | 12 ++++++++---- .../Desktop/Apps/Host Manager/HostManagerEditor.tsx | 2 -- src/ui/Desktop/Apps/Terminal/Terminal.tsx | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/backend/database/routes/ssh.ts b/src/backend/database/routes/ssh.ts index da00dfd7..cf75f4f0 100644 --- a/src/backend/database/routes/ssh.ts +++ b/src/backend/database/routes/ssh.ts @@ -1239,15 +1239,19 @@ async function resolveHostCredentials(host: any): Promise { }; } } - - // Convert snake_case to camelCase for hosts without credentials + + const result = { ...host }; + if (host.key_password !== undefined) { + if (result.keyPassword === undefined) { + result.keyPassword = host.key_password; + } + delete result.key_password; + } const result = { ...host }; if (host.key_password !== undefined) { - // Only use the inline key_password if keyPassword hasn't been set by credential resolution if (result.keyPassword === undefined) { result.keyPassword = host.key_password; } - // Always remove the snake_case version to standardize the output delete result.key_password; } return result; diff --git a/src/ui/Desktop/Apps/Host Manager/HostManagerEditor.tsx b/src/ui/Desktop/Apps/Host Manager/HostManagerEditor.tsx index ad8e8d99..0fe881ef 100644 --- a/src/ui/Desktop/Apps/Host Manager/HostManagerEditor.tsx +++ b/src/ui/Desktop/Apps/Host Manager/HostManagerEditor.tsx @@ -877,8 +877,6 @@ export function HostManagerEditor({ | "credential"; setAuthTab(newAuthType); form.setValue("authType", newAuthType); - // Don't clear other auth fields - let them persist - // The backend will only use the fields relevant to the selected authType }} className="flex-1 flex flex-col h-full min-h-0" > diff --git a/src/ui/Desktop/Apps/Terminal/Terminal.tsx b/src/ui/Desktop/Apps/Terminal/Terminal.tsx index c4553b59..2de03a7d 100644 --- a/src/ui/Desktop/Apps/Terminal/Terminal.tsx +++ b/src/ui/Desktop/Apps/Terminal/Terminal.tsx @@ -512,7 +512,8 @@ export const Terminal = forwardRef(function SSHTerminal( cursorStyle: "bar", scrollback: 10000, fontSize: 14, - fontFamily: '"Caskaydia Cove Nerd Font Mono", "SF Mono", Consolas, "Liberation Mono", monospace', + fontFamily: + '"Caskaydia Cove Nerd Font Mono", "SF Mono", Consolas, "Liberation Mono", monospace', theme: { background: "#18181b", foreground: "#f7f7f7" }, allowTransparency: true, convertEol: true, -- 2.49.1