Skip to content

Commit 4c9713b

Browse files
authored
ec2: add new command for remote connect (#3649)
Problem: We need an entry point for the remote connect functionality and a clear distinction between openTerminal and openRemoteConnection. Solution: change aws.ec2.connectToInstance to aws.ec2.openTerminal. (inline with ecs naming.) add new command aws.ec2.openRemoteConnecton. (inline with CodeCatalyst naming) make command accessible from the command palette. allow aws.ec2.openRemoteConnection to be empty. refactor code to make clear which parts are specific to terminal and which are for general connection.
1 parent e8e6d75 commit 4c9713b

File tree

6 files changed

+47
-41
lines changed

6 files changed

+47
-41
lines changed

package.json

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,11 @@
11111111
"command": "aws.auth.manageConnections"
11121112
},
11131113
{
1114-
"command": "aws.ec2.connectToInstance",
1114+
"command": "aws.ec2.openRemoteConnection",
1115+
"when": "aws.isDevMode"
1116+
},
1117+
{
1118+
"command": "aws.ec2.openTerminal",
11151119
"when": "aws.isDevMode"
11161120
},
11171121
{
@@ -1309,7 +1313,7 @@
13091313
"group": "inline@1"
13101314
},
13111315
{
1312-
"command": "aws.ec2.connectToInstance",
1316+
"command": "aws.ec2.openTerminal",
13131317
"group": "0@1",
13141318
"when": "viewItem == awsEc2Node"
13151319
},
@@ -2056,8 +2060,18 @@
20562060
}
20572061
},
20582062
{
2059-
"command": "aws.ec2.connectToInstance",
2060-
"title": "%AWS.command.ec2.connectToInstance%",
2063+
"command": "aws.ec2.openTerminal",
2064+
"title": "%AWS.command.ec2.openTerminal%",
2065+
"category": "%AWS.title%",
2066+
"cloud9": {
2067+
"cn": {
2068+
"category": "%AWS.title.cn%"
2069+
}
2070+
}
2071+
},
2072+
{
2073+
"command": "aws.ec2.openRemoteConnection",
2074+
"title": "%AWS.command.ec2.openRemoteConnection%",
20612075
"category": "%AWS.title%",
20622076
"cloud9": {
20632077
"cn": {

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@
108108
"AWS.command.refreshAwsExplorer": "Refresh Explorer",
109109
"AWS.command.refreshCdkExplorer": "Refresh CDK Explorer",
110110
"AWS.command.cdk.help": "View CDK Documentation",
111-
"AWS.command.ec2.connectToInstance": "Connect to EC2 Instance...",
111+
"AWS.command.ec2.openTerminal": "Open terminal to EC2 instance...",
112+
"AWS.command.ec2.openRemoteConnection": "Connect to EC2 instance in New Window...",
112113
"AWS.command.ecr.copyTagUri": "Copy Tag URI",
113114
"AWS.command.ecr.copyRepositoryUri": "Copy Repository URI",
114115
"AWS.command.ecr.createRepository": "Create Repository...",

src/ec2/activation.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,27 @@
44
*/
55
import { ExtContext } from '../shared/extensions'
66
import { Commands } from '../shared/vscode/commands2'
7-
import { tryConnect } from './commands'
87
import { telemetry } from '../shared/telemetry/telemetry'
98
import { Ec2InstanceNode } from './explorer/ec2InstanceNode'
9+
import { promptUserForEc2Selection } from './prompter'
10+
import { Ec2ConnectionManager } from './model'
1011

1112
export async function activate(ctx: ExtContext): Promise<void> {
1213
ctx.extensionContext.subscriptions.push(
13-
Commands.register('aws.ec2.connectToInstance', async (node?: Ec2InstanceNode) => {
14+
Commands.register('aws.ec2.openTerminal', async (node?: Ec2InstanceNode) => {
1415
await telemetry.ec2_connectToInstance.run(async span => {
1516
span.record({ ec2ConnectionType: 'ssm' })
16-
await (node ? tryConnect(node.toSelection()) : tryConnect())
17+
const selection = node ? node.toSelection() : await promptUserForEc2Selection()
18+
19+
const connectionManager = new Ec2ConnectionManager(selection.region)
20+
await connectionManager.attemptToOpenEc2Terminal(selection)
1721
})
22+
}),
23+
24+
Commands.register('aws.ec2.openRemoteConnection', async (node?: Ec2InstanceNode) => {
25+
const selection = node ? node.toSelection() : await promptUserForEc2Selection()
26+
//const connectionManager = new Ec2ConnectionManager(selection.region)
27+
console.log(selection)
1828
})
1929
)
2030
}

src/ec2/commands.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/ec2/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class Ec2ConnectionManager {
113113
})
114114
}
115115

116-
public async attemptEc2Connection(selection: Ec2Selection): Promise<void> {
116+
public async attemptToOpenEc2Terminal(selection: Ec2Selection): Promise<void> {
117117
await this.checkForStartSessionError(selection)
118118
try {
119119
const response = await this.ssmClient.startSession(selection.instanceId)

src/ec2/prompter.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { RegionSubmenu, RegionSubmenuResponse } from '../shared/ui/common/region
77
import { Ec2Selection, getInstancesFromRegion } from './utils'
88
import { DataQuickPickItem } from '../shared/ui/pickerPrompter'
99
import { Ec2Instance } from '../shared/clients/ec2Client'
10+
import { isValidResponse } from '../shared/wizards/wizard'
11+
import { CancellationError } from '../shared/utilities/timeoutUtils'
1012

1113
function asQuickpickItem(instance: Ec2Instance): DataQuickPickItem<string> {
1214
return {
@@ -16,6 +18,17 @@ function asQuickpickItem(instance: Ec2Instance): DataQuickPickItem<string> {
1618
}
1719
}
1820

21+
export async function promptUserForEc2Selection(): Promise<Ec2Selection> {
22+
const prompter = createEc2ConnectPrompter()
23+
const response = await prompter.prompt()
24+
25+
if (isValidResponse(response)) {
26+
return handleEc2ConnectPrompterResponse(response)
27+
} else {
28+
throw new CancellationError('user')
29+
}
30+
}
31+
1932
export function handleEc2ConnectPrompterResponse(response: RegionSubmenuResponse<string>): Ec2Selection {
2033
return {
2134
instanceId: response.data,

0 commit comments

Comments
 (0)