mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-06 08:07:49 +00:00
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.
26 lines
1.2 KiB
TypeScript
26 lines
1.2 KiB
TypeScript
/** 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;
|
||
}
|