(host: string)
| 268 | } |
| 269 | |
| 270 | export async function resolveSSHConfig(host: string): Promise<ResolvedSSHConfig> { |
| 271 | const { host: hostAlias, user: userOverride } = parseHostAndUser(host); |
| 272 | const homeDir = getHomeDir(); |
| 273 | |
| 274 | const config = await loadSSHConfig(); |
| 275 | const computed = config |
| 276 | ? userOverride |
| 277 | ? config.compute({ Host: hostAlias, User: userOverride }) |
| 278 | : config.compute(hostAlias) |
| 279 | : {}; |
| 280 | |
| 281 | const hostName = toStringValue(getConfigValue(computed, "HostName")) ?? hostAlias; |
| 282 | const userFromConfig = toStringValue(getConfigValue(computed, "User")); |
| 283 | |
| 284 | if (config) { |
| 285 | // Default to local username for %r expansion if no User is specified |
| 286 | const matchExecUser = userOverride ?? userFromConfig ?? getDefaultUsername(); |
| 287 | applyNegatedExecMatch(config, hostName, matchExecUser, computed); |
| 288 | } |
| 289 | |
| 290 | const portValue = toStringValue(getConfigValue(computed, "Port")); |
| 291 | const identityValues = toStringArray(getConfigValue(computed, "IdentityFile")); |
| 292 | const proxyCommandRaw = toStringValue(getConfigValue(computed, "ProxyCommand")); |
| 293 | |
| 294 | const port = portValue ? Number.parseInt(portValue, 10) : DEFAULT_SSH_PORT; |
| 295 | |
| 296 | const identityFiles = identityValues.map((value) => normalizeIdentityFile(value, homeDir)); |
| 297 | |
| 298 | const proxyCommand = |
| 299 | proxyCommandRaw && proxyCommandRaw.toLowerCase() !== "none" |
| 300 | ? proxyCommandRaw.trim() |
| 301 | : undefined; |
| 302 | |
| 303 | return { |
| 304 | host: hostAlias, |
| 305 | hostName, |
| 306 | user: userOverride ?? userFromConfig, |
| 307 | port: Number.isFinite(port) ? port : DEFAULT_SSH_PORT, |
| 308 | identityFiles, |
| 309 | proxyCommand, |
| 310 | }; |
| 311 | } |
no test coverage detected