diff --git a/apps/desktop/src/components/connection/ConnectionDialog.vue b/apps/desktop/src/components/connection/ConnectionDialog.vue index 5869685352..9117f12de3 100644 --- a/apps/desktop/src/components/connection/ConnectionDialog.vue +++ b/apps/desktop/src/components/connection/ConnectionDialog.vue @@ -23,6 +23,7 @@ import type { NacosAdminConfig, NacosAuthConfig, NacosImplementation, NacosMetri import { CONNECTION_ATTEMPT_CANCELLED_MESSAGE, useConnectionStore } from "@/stores/connectionStore"; import { useTunnelProfileStore } from "@/stores/tunnelProfileStore"; import { detachTunnelProfileLayer, tunnelProfileReferenceLayer, tunnelProfileSummary } from "@/lib/connection/tunnelProfiles"; +import { applySshAuthMethod, inferSshAuthMethod } from "@/lib/connection/sshAuthMethod"; import { applySshConfigHostAliasPrefill as prefillSshConfigHostAlias } from "@/lib/connection/sshConfigHosts"; import { canPersistConnectionTestResult, connectionEditDraftSyncAction } from "./connectionEditDraftSync"; import { createConnectionNoteVisibilityDraft, persistConnectionNoteVisibilityDraft as persistConnectionNoteVisibilityDraftState, resetConnectionNoteVisibilityDraft, setConnectionNoteVisibilityDraft, syncConnectionNoteVisibilityDraft } from "./connectionNoteVisibilityDraft"; @@ -372,20 +373,6 @@ function defaultSshTunnel(): SshTunnelConfig { }; } -/** - * Infers a login method for connections saved before `auth_method` existed - * (or imported from a source that never set it), so the dropdown shows a - * sensible current state instead of defaulting blindly to "password". - * Mirrors the priority `connect_and_authenticate` actually uses at connect - * time (key > password > agent > none) — see `db/ssh_tunnel.rs`. - */ -function inferSshAuthMethod(hop: Partial): "password" | "key" | "agent" | "none" { - if (hop.key_path?.trim()) return "key"; - if (hop.password) return "password"; - if (hop.use_ssh_agent) return "agent"; - return "none"; -} - function normalizeSshTunnel(hop: Partial): SshTunnelConfig { return { id: hop.id || uuid(), @@ -4964,31 +4951,10 @@ function updateSelectedProxyType(value: unknown) { resetTestState(); } -/** - * "agent" is legacy-only: it's never chosen from this dropdown, only ever - * inherited from a connection saved before this selector existed. Once the - * user picks something else, the option (and its underlying checkbox) is - * gone from the form for good. - */ -function isLegacySshAgentMethod(hop: Partial | null | undefined) { - return hop?.auth_method === "agent"; -} - function updateSelectedSshAuthMethod(value: unknown) { const layer = selectedSshLayer.value; if (!layer) return; - layer.auth_method = value === "key" ? "key" : value === "key+password" ? "key+password" : value === "none" ? "none" : "password"; - // Scrub credential fields that do not apply to the selected method so - // they are not accidentally submitted or used by the backend fallback. - // "key+password" keeps both key and password fields. - if (layer.auth_method !== "password" && layer.auth_method !== "key+password") layer.password = ""; - if (layer.auth_method !== "key" && layer.auth_method !== "key+password") { - layer.key_path = ""; - layer.key_passphrase = ""; - } - if (layer.auth_method !== "key" && layer.auth_method !== "key+password") { - layer.use_ssh_agent = false; - } + applySshAuthMethod(layer, value); resetTestState(); } @@ -8085,8 +8051,8 @@ function openExternalUrl(url: string) { {{ t("connection.sshAuthMethodPassword") }} {{ t("connection.sshAuthMethodKey") }} {{ t("connection.sshAuthMethodKeyPassword") }} + {{ t("connection.sshUseAgent") }} {{ t("connection.sshAuthMethodNone") }} - {{ t("connection.sshAuthMethodAgentLegacy") }} @@ -8116,19 +8082,10 @@ function openExternalUrl(url: string) {

{{ t("connection.sshAuthMethodNoneHint") }}

- +
+ + +