File tree Expand file tree Collapse file tree 4 files changed +33
-9
lines changed Expand file tree Collapse file tree 4 files changed +33
-9
lines changed Original file line number Diff line number Diff line change 1308
1308
"when" : " viewItem == awsCodeCatalystNodeSaved" ,
1309
1309
"group" : " inline@1"
1310
1310
},
1311
+ {
1312
+ "command" : " aws.ec2.connectToInstance" ,
1313
+ "group" : " 0@1" ,
1314
+ "when" : " viewItem == awsEc2Node"
1315
+ },
1311
1316
{
1312
1317
"command" : " aws.ecr.createRepository" ,
1313
1318
"when" : " view == aws.explorer && viewItem == awsEcrNode" ,
Original file line number Diff line number Diff line change @@ -6,13 +6,14 @@ import { ExtContext } from '../shared/extensions'
6
6
import { Commands } from '../shared/vscode/commands2'
7
7
import { tryConnect } from './commands'
8
8
import { telemetry } from '../shared/telemetry/telemetry'
9
+ import { Ec2InstanceNode } from './explorer/ec2InstanceNode'
9
10
10
11
export async function activate ( ctx : ExtContext ) : Promise < void > {
11
12
ctx . extensionContext . subscriptions . push (
12
- Commands . register ( 'aws.ec2.connectToInstance' , async ( param ?: unknown ) => {
13
+ Commands . register ( 'aws.ec2.connectToInstance' , async ( node ?: Ec2InstanceNode ) => {
13
14
await telemetry . ec2_connectToInstance . run ( async span => {
14
15
span . record ( { ec2ConnectionType : 'ssm' } )
15
- await tryConnect ( )
16
+ await ( node ? tryConnect ( node . toSelection ( ) ) : tryConnect ( ) )
16
17
} )
17
18
} )
18
19
)
Original file line number Diff line number Diff line change 6
6
import { createEc2ConnectPrompter , handleEc2ConnectPrompterResponse } from './prompter'
7
7
import { isValidResponse } from '../shared/wizards/wizard'
8
8
import { Ec2ConnectionManager } from './model'
9
+ import { Ec2Selection } from './utils'
10
+ import { RegionSubmenuResponse } from '../shared/ui/common/regionSubmenu'
11
+ import { PromptResult } from '../shared/ui/prompter'
9
12
import { CancellationError } from '../shared/utilities/timeoutUtils'
10
13
11
- export async function tryConnect ( ) : Promise < void > {
12
- const prompter = createEc2ConnectPrompter ( )
13
- const response = await prompter . prompt ( )
14
-
14
+ function getSelectionFromResponse ( response : PromptResult < RegionSubmenuResponse < string > > ) : Ec2Selection {
15
15
if ( isValidResponse ( response ) ) {
16
- const selection = handleEc2ConnectPrompterResponse ( response )
17
- const ec2Client = new Ec2ConnectionManager ( selection . region )
18
- await ec2Client . attemptEc2Connection ( selection )
16
+ return handleEc2ConnectPrompterResponse ( response )
19
17
} else {
20
18
throw new CancellationError ( 'user' )
21
19
}
22
20
}
21
+
22
+ export async function tryConnect ( selection ?: Ec2Selection ) : Promise < void > {
23
+ if ( ! selection ) {
24
+ const prompter = createEc2ConnectPrompter ( )
25
+ const response = await prompter . prompt ( )
26
+
27
+ selection = getSelectionFromResponse ( response )
28
+ }
29
+
30
+ const ec2Client = new Ec2ConnectionManager ( selection . region )
31
+ await ec2Client . attemptEc2Connection ( selection )
32
+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { AWSTreeNodeBase } from '../../shared/treeview/nodes/awsTreeNodeBase'
9
9
import { Ec2Instance } from '../../shared/clients/ec2Client'
10
10
import { build } from '@aws-sdk/util-arn-parser'
11
11
import globals from '../../shared/extensionGlobals'
12
+ import { Ec2Selection } from '../utils'
12
13
13
14
export class Ec2InstanceNode extends AWSTreeNodeBase implements AWSResourceNode {
14
15
public constructor (
@@ -31,6 +32,13 @@ export class Ec2InstanceNode extends AWSTreeNodeBase implements AWSResourceNode
31
32
this . instance = newInstance
32
33
}
33
34
35
+ public toSelection ( ) : Ec2Selection {
36
+ return {
37
+ region : this . regionCode ,
38
+ instanceId : this . InstanceId ,
39
+ }
40
+ }
41
+
34
42
public get name ( ) : string {
35
43
return getNameOfInstance ( this . instance ) ?? 'Unnamed instance'
36
44
}
You can’t perform that action at this time.
0 commit comments