MCPcopy Index your code
hub / github.com/coder/mux / resolveSSHConfig

Function resolveSSHConfig

src/node/runtime/sshConfigParser.ts:270–311  ·  view source on GitHub ↗
(host: string)

Source from the content-addressed store, hash-verified

268}
269
270export 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}

Callers 2

connectMethod · 0.90

Calls 9

parseHostAndUserFunction · 0.85
loadSSHConfigFunction · 0.85
toStringValueFunction · 0.85
getConfigValueFunction · 0.85
applyNegatedExecMatchFunction · 0.85
toStringArrayFunction · 0.85
normalizeIdentityFileFunction · 0.85
getHomeDirFunction · 0.70
getDefaultUsernameFunction · 0.70

Tested by

no test coverage detected