Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.1 KB
Raw Blame
import type { SshConfigHostEntry, SshTunnelConfig } from "@/types/database";

const DEFAULT_SSH_USER = "root";
const DEFAULT_SSH_PORT = 22;

/**
 * Prefills an SSH form from a matching ~/.ssh/config alias without
 * overwriting values the user already changed away from the form defaults.
 * The Rust backend remains responsible for authoritative alias resolution at
 * connect time; this helper only keeps the form preview consistent.
 */
export function applySshConfigHostAliasPrefill(target: SshTunnelConfig, hosts: readonly SshConfigHostEntry[]): void {
  const entry = hosts.find((candidate) => candidate.alias === target.host);
  if (!entry) return;
  if (target.user === DEFAULT_SSH_USER && entry.user) target.user = entry.user;
  if (target.port === DEFAULT_SSH_PORT && entry.port) target.port = entry.port;
  if (!target.key_path && entry.identity_file) {
    target.key_path = entry.identity_file;
    if ((!target.auth_method || target.auth_method === "password") && !target.password?.trim()) {
      target.auth_method = "key";
    }
  }
  if (!target.proxy_command && entry.proxy_command) target.proxy_command = entry.proxy_command;
}