Skip to content

Commit 0d0aff3

Browse files
committed
slighly improved ssh-config usage with less casting
Signed-off-by: Jonah Iden <[email protected]>
1 parent 3c68661 commit 0d0aff3

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

packages/remote/src/electron-browser/remote-ssh-contribution.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { inject, injectable } from '@theia/core/shared/inversify';
1919
import { RemoteSSHConnectionProvider } from '../electron-common/remote-ssh-connection-provider';
2020
import { AbstractRemoteRegistryContribution, RemoteRegistry } from './remote-registry-contribution';
2121
import { RemotePreferences } from './remote-preferences';
22-
import * as SshConfig from 'ssh-config';
22+
import SSHConfig, { Directive } from 'ssh-config';
2323

2424
export namespace RemoteSSHCommands {
2525
export const CONNECT: Command = Command.toLocalizedCommand({
@@ -76,11 +76,17 @@ export class RemoteSSHContribution extends AbstractRemoteRegistryContribution {
7676

7777
const wildcardCheck = /[\?\*\%]/;
7878

79-
for (const record of <SshConfig.Section[]>sshConfig) {
80-
if (record.param.toLowerCase() === 'host' && !wildcardCheck.test(<string>record.value)) {
81-
const rec: Record<string, string | string[]> = (<SshConfig.Directive[]>record.config).reduce(
82-
(pv, item) => ({ ...pv, [item.param.toLowerCase()]: item.value }), { 'host': <string>record.value }
83-
);
79+
for (const record of sshConfig) {
80+
// check if its a section and if it has a single value
81+
if (!('config' in record) || !(typeof record.value === 'string')) {
82+
continue;
83+
}
84+
if (record.param.toLowerCase() === 'host' && !wildcardCheck.test(record.value)) {
85+
const rec: Record<string, string | string[]> = ((record.config)
86+
.filter((entry): entry is Directive => entry.type === SSHConfig.DIRECTIVE))
87+
.reduce(
88+
(pv, item) => ({ ...pv, [item.param.toLowerCase()]: item.value }), { 'host': record.value }
89+
);
8490
const host = (rec.hostname || rec.host) + ':' + (rec.port || '22');
8591
const user = rec.user || 'root';
8692

0 commit comments

Comments
 (0)