Skip to content

Commit

Permalink
Merge pull request #69 from clemyan/fix-ssh-config
Browse files Browse the repository at this point in the history
Fix ssh config resolution
  • Loading branch information
Natizyskunk authored Oct 27, 2021
2 parents 98ff0d4 + cdd52eb commit e0d2bcb
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/core/fileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,36 +233,30 @@ function mergeConfigWithExternalRefer(
}

const parsedSSHConfig = sshConfig.parse(sshConfigContent);
const section = parsedSSHConfig.find({
Host: copyed.host,
});

if (section === null) {
return copyed;
}
const computed = parsedSSHConfig.compute(copyed.host);

const mapping = new Map([
['hostname', 'host'],
['port', 'port'],
['user', 'username'],
['identityfile', 'privateKeyPath'],
['serveraliveinterval', 'keepalive'],
['connecttimeout', 'connTimeout'],
]);

section.config.forEach(line => {
if (!line.param) {
Object.entries<any>(computed).forEach(([param, value]) => {
if (param.toLowerCase() === 'identityfile') {
setConfigValue(copyed, 'privateKeyPath', value[0]);
return;
}

const key = mapping.get(line.param.toLowerCase());
const key = mapping.get(param.toLowerCase());

if (key !== undefined) {
// don't need consider config priority, always set to the resolve host.
if (key === 'host') {
copyed[key] = line.value;
copyed[key] = value;
} else {
setConfigValue(copyed, key, line.value);
setConfigValue(copyed, key, value);
}
}
});
Expand Down

0 comments on commit e0d2bcb

Please sign in to comment.