Skip to content

Commit 3ff2453

Browse files
committed
layout implementation
1 parent 545dc4f commit 3ff2453

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

packages/core/src/awsService/ec2/model.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ import {
2020
} from '../../shared/remoteSession'
2121
import { DefaultIamClient } from '../../shared/clients/iamClient'
2222
import { ErrorInformation } from '../../shared/errors'
23-
import { sshAgentSocketVariable, startSshAgent, startVscodeRemote } from '../../shared/extensions/ssh'
23+
import {
24+
sshAgentSocketVariable,
25+
startSshAgent,
26+
startVscodeRemote,
27+
testSshConnection,
28+
} from '../../shared/extensions/ssh'
2429
import { createBoundProcess } from '../../codecatalyst/model'
2530
import { getLogger } from '../../shared/logger/logger'
2631
import { CancellationError, Timeout } from '../../shared/utilities/timeoutUtils'
@@ -195,6 +200,7 @@ export class Ec2Connecter implements vscode.Disposable {
195200
const remoteEnv = await this.prepareEc2RemoteEnvWithProgress(selection, remoteUser)
196201

197202
try {
203+
await testSshConnection(remoteEnv.sshPath, remoteEnv.hostname)
198204
await startVscodeRemote(remoteEnv.SessionProcess, remoteEnv.hostname, '/', remoteEnv.vscPath, remoteUser)
199205
} catch (err) {
200206
this.throwGeneralConnectionError(selection, err as Error)
@@ -212,8 +218,9 @@ export class Ec2Connecter implements vscode.Disposable {
212218
const logger = this.configureRemoteConnectionLogger(selection.instanceId)
213219
const { ssm, vsc, ssh } = (await ensureDependencies()).unwrap()
214220
const keyPair = await this.configureSshKeys(selection, remoteUser)
215-
const hostNamePrefix = 'aws-ec2-'
216-
const sshConfig = new SshConfig(ssh, hostNamePrefix, 'ec2_connect', keyPair.getPrivateKeyPath())
221+
const hostnamePrefix = 'aws-ec2-'
222+
const hostname = `${hostnamePrefix}${selection.instanceId}`
223+
const sshConfig = new SshConfig(ssh, hostnamePrefix, 'ec2_connect', keyPair.getPrivateKeyPath())
217224

218225
const config = await sshConfig.ensureValid()
219226
if (config.isErr()) {
@@ -222,6 +229,7 @@ export class Ec2Connecter implements vscode.Disposable {
222229

223230
throw err
224231
}
232+
225233
const ssmSession = await this.ssmClient.startSession(selection.instanceId, 'AWS-StartSSHSession')
226234
await this.addActiveSession(selection.instanceId, ssmSession.SessionId!)
227235

@@ -236,7 +244,7 @@ export class Ec2Connecter implements vscode.Disposable {
236244
})
237245

238246
return {
239-
hostname: `${hostNamePrefix}${selection.instanceId}`,
247+
hostname,
240248
envProvider,
241249
sshPath: ssh,
242250
vscPath: vsc,

packages/core/src/shared/extensions/ssh.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as path from 'path'
88
import * as nls from 'vscode-nls'
99
import fs from '../fs/fs'
1010
import { getLogger } from '../logger'
11-
import { ChildProcess } from '../utilities/processUtils'
11+
import { ChildProcess, ChildProcessOptions } from '../utilities/processUtils'
1212
import { ArrayConstructor, NonNullObject } from '../utilities/typeConstructors'
1313
import { Settings } from '../settings'
1414
import { VSCODE_EXTENSION_ID } from '../extensions'
@@ -119,6 +119,16 @@ export class RemoteSshSettings extends Settings.define('remote.SSH', remoteSshTy
119119
}
120120
}
121121

122+
export async function testSshConnection(
123+
sshPath: string,
124+
hostname: string,
125+
options: ChildProcessOptions = {}
126+
): Promise<void> {
127+
const process = new ChildProcess(sshPath, ['-T', hostname], options)
128+
const result = await process.run()
129+
console.log(result)
130+
}
131+
122132
export async function startVscodeRemote(
123133
ProcessClass: typeof ChildProcess,
124134
hostname: string,

0 commit comments

Comments
 (0)