Files
openidea/src/features/settings/pages/sshConnection.ts
T
l0ng-ai 0411a5b08a fix(settings): show SSH password and passphrase inputs (#609)
The SSH configuration form only asked for a password after a failed Test Connection, so choosing Password showed nothing but a "Save password" checkbox. It now shows a Password row, or a Passphrase row for key pairs.

The typed secret is staged with the other settings changes: it is written on Apply / OK and discarded on Cancel or Reset, and Test Connection uses it without storing it. An emptied field leaves the stored secret alone. Deployment, run target and data source forms have their own secret inputs and are unchanged.
2026-11-01 03:33:25 +08:00

26 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** Test Connection of Settings › Tools › SSH Configurations: what a failure asks of the user. */
import type { SshAuthValid } from "@/platform/remoteSettings";
export type SshTestRemedy = "trustHostKey" | "secret" | null;
/**
* An unknown host key to confirm, or a missing / rejected password or key
* passphrase to type. A changed host key is never offered for trust.
*/
export function sshTestRemedy(kind: string | undefined, message: string, auth: SshAuthValid): SshTestRemedy {
if (/^Unknown SSH host key/.test(message)) return "trustHostKey";
if (kind !== "permissionDenied") return null;
if (/^SSH host key .* has changed/.test(message)) return null;
if (/^SSH (password|key passphrase) required|^cannot decrypt SSH key/.test(message)) return "secret";
// With OpenSSH config + agent there is nothing to type unless a key is encrypted.
if (/^SSH authentication failed/.test(message)) return auth === "openSsh" ? null : "secret";
return null;
}
/** A port typed in the Port field (empty or invalid: the default). */
export function parseSshPort(text: string): number | null {
if (!/^\s*\d+\s*$/.test(text)) return null;
const n = parseInt(text, 10);
return n > 0 && n <= 65535 ? n : null;
}