mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-17 13:01:24 +00:00
* fix(#3475): automated AI fix * fix: address Codex review on PR #3477 * fix: keep SSH identity picker state accurate * style: keep SSH identity picker source ASCII-only * fix: require usernames for saved SSH identity retries * Keep selected SSH identity for terminal SFTP * Share reauthenticated identity with all terminal SFTP entry points * Pass SFTP identity source setter into layer effects * Use effective identity for preset SFTP panel * fix: keep focused SFTP identity in sync for toggle * fix(terminal): use selected vault identity without exposing password --------- Co-authored-by: netcatty-bot <308658023+netcatty-bot@users.noreply.github.com> Co-authored-by: bincxz <16399091+binaricat@users.noreply.github.com>
38 lines
1.6 KiB
TypeScript
38 lines
1.6 KiB
TypeScript
import type { Host, Identity } from "./models";
|
|
import { sanitizeCredentialValue } from "./credentials";
|
|
|
|
/**
|
|
* Saved password identities that can be reused from the terminal
|
|
* re-authentication dialog. Only identities carrying a usable stored
|
|
* password and username qualify. Key identities are already selectable
|
|
* through the existing SSH key picker (#3475). Undecryptable vault ciphertext
|
|
* (`enc:v1:` placeholders left when hydration fails) is filtered out so
|
|
* those identities fall back to manual password re-entry.
|
|
*/
|
|
export const listPasswordAuthIdentities = (
|
|
identities: readonly Identity[] | undefined,
|
|
): Identity[] =>
|
|
(identities ?? []).filter(
|
|
(identity) =>
|
|
identity.authMethod === "password"
|
|
&& typeof identity.username === "string"
|
|
&& identity.username.trim().length > 0
|
|
&& typeof identity.password === "string"
|
|
&& (sanitizeCredentialValue(identity.password) ?? "").length > 0,
|
|
);
|
|
|
|
/** Use the temporary saved identity for SFTP opened from its authenticated terminal. */
|
|
export const resolvePasswordAuthSftpHost = (
|
|
host: Host,
|
|
identities: readonly Identity[] | undefined,
|
|
auth: { authMethod: string; username: string; password?: string; savedToHost?: boolean } | null,
|
|
): Host => {
|
|
if (!auth || auth.authMethod !== "password" || auth.savedToHost) return host;
|
|
const identity = listPasswordAuthIdentities(identities).find(
|
|
(candidate) => candidate.username === auth.username && candidate.password === auth.password,
|
|
);
|
|
return identity
|
|
? { ...host, username: identity.username, identityId: identity.id }
|
|
: host;
|
|
};
|