From c90e15327872ebe5b7109bd91a3cb582c18c4aef Mon Sep 17 00:00:00 2001 From: Philip Langer Date: Fri, 19 Jan 2024 21:07:26 +0100 Subject: [PATCH] Support specifying the port of a remote SSH connection Contributed on behalf of STMicroelectronics. Fixes https://github.com/eclipse-theia/theia/issues/13295 Change-Id: If29f06b34749091797ae861101159195afcc5a8e --- CHANGELOG.md | 1 + .../ssh/remote-ssh-connection-provider.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 459ea9036d021..58983f80d9706 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - [terminal] rename terminal.sendText() parameter from addNewLine to shouldExecute [#13236](https://github.com/eclipse-theia/theia/pull/13236) - contributed on behalf of STMicroelectronics - [terminal] update terminalQuickFixProvider proposed API according to vscode 1.85 version [#13240](https://github.com/eclipse-theia/theia/pull/13240) - contributed on behalf of STMicroelectronics - [core] added preference 'workbench.tree.indent' to control the indentation in the tree widget [#13179](https://github.com/eclipse-theia/theia/pull/13179) - contributed on behalf of STMicroelectronics +- [remote] upport specifying the port of a remote SSH connection [#13296](https://github.com/eclipse-theia/theia/pull/13296) - contributed on behalf of STMicroelectronics [Breaking Changes:](#breaking_changes_not_yet_released) diff --git a/packages/remote/src/electron-node/ssh/remote-ssh-connection-provider.ts b/packages/remote/src/electron-node/ssh/remote-ssh-connection-provider.ts index 2f942de3c9a0f..3de1a97bea596 100644 --- a/packages/remote/src/electron-node/ssh/remote-ssh-connection-provider.ts +++ b/packages/remote/src/electron-node/ssh/remote-ssh-connection-provider.ts @@ -86,13 +86,14 @@ export class RemoteSSHConnectionProviderImpl implements RemoteSSHConnectionProvi const deferred = new Deferred(); const sshClient = new ssh2.Client(); const identityFiles = await this.identityFileCollector.gatherIdentityFiles(); - const sshAuthHandler = this.getAuthHandler(user, host, identityFiles); + const hostUrl = new URL(`ssh://${host}`); + const sshAuthHandler = this.getAuthHandler(user, hostUrl.hostname, identityFiles); sshClient .on('ready', async () => { const connection = new RemoteSSHConnection({ client: sshClient, id: v4(), - name: host, + name: hostUrl.hostname, type: 'SSH' }); try { @@ -102,11 +103,12 @@ export class RemoteSSHConnectionProviderImpl implements RemoteSSHConnectionProvi deferred.reject(err); } }).on('end', () => { - console.log(`Ended remote connection to host '${user}@${host}'`); + console.log(`Ended remote connection to host '${user}@${hostUrl.hostname}'`); }).on('error', err => { deferred.reject(err); }).connect({ - host: host, + host: hostUrl.hostname, + port: hostUrl.port ? parseInt(hostUrl.port, 10) : undefined, username: user, authHandler: (methodsLeft, successes, callback) => (sshAuthHandler(methodsLeft, successes, callback), undefined) });