Skip to content

Commit c94acfd

Browse files
authored
feat(ec2): add menu actions on explorer nodes #3644
* Add copy ARN, copy Name, copy instanceId actions to EC2 menu. * generalize copyName/copyArn/etc to one copyText() function.
1 parent d52e00f commit c94acfd

File tree

11 files changed

+79
-124
lines changed

11 files changed

+79
-124
lines changed

package.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,11 @@
14141414
"when": "!config.aws.samcli.legacyDeploy && view == aws.explorer && viewItem =~ /^(awsLambdaNode|awsRegionNode|awsCloudFormationRootNode)$/",
14151415
"group": "1@2"
14161416
},
1417+
{
1418+
"command": "aws.ec2.copyInstanceId",
1419+
"when": "view == aws.explorer && viewItem == awsEc2Node",
1420+
"group": "2@0"
1421+
},
14171422
{
14181423
"command": "aws.ecr.copyTagUri",
14191424
"when": "view == aws.explorer && viewItem == awsEcrTagNode",
@@ -1601,12 +1606,12 @@
16011606
},
16021607
{
16031608
"command": "aws.copyName",
1604-
"when": "view == aws.explorer && viewItem =~ /^(awsRegionFunctionNode|awsRegionFunctionNodeDownloadable|awsCloudFormationFunctionNode|awsStateMachineNode|awsCloudFormationNode|awsS3BucketNode|awsS3FolderNode|awsS3FileNode|awsApiGatewayNode|awsIotThingNode)$|^(awsAppRunnerServiceNode|awsIotCertificateNode|awsIotPolicyNode|awsIotPolicyVersionNode)/",
1609+
"when": "view == aws.explorer && viewItem =~ /^(awsRegionFunctionNode|awsRegionFunctionNodeDownloadable|awsCloudFormationFunctionNode|awsStateMachineNode|awsCloudFormationNode|awsS3BucketNode|awsS3FolderNode|awsS3FileNode|awsApiGatewayNode|awsIotThingNode)$|^(awsAppRunnerServiceNode|awsIotCertificateNode|awsIotPolicyNode|awsIotPolicyVersionNode|awsEc2Node)/",
16051610
"group": "2@1"
16061611
},
16071612
{
16081613
"command": "aws.copyArn",
1609-
"when": "view == aws.explorer && viewItem =~ /^(awsRegionFunctionNode|awsRegionFunctionNodeDownloadable|awsCloudFormationFunctionNode|awsStateMachineNode|awsCloudFormationNode|awsCloudWatchLogNode|awsS3BucketNode|awsS3FolderNode|awsS3FileNode|awsApiGatewayNode|awsEcrRepositoryNode|awsIotThingNode)$|^(awsAppRunnerServiceNode|awsEcsServiceNode|awsIotCertificateNode|awsIotPolicyNode|awsIotPolicyVersionNode|awsMdeInstanceNode)/",
1614+
"when": "view == aws.explorer && viewItem =~ /^(awsRegionFunctionNode|awsRegionFunctionNodeDownloadable|awsCloudFormationFunctionNode|awsStateMachineNode|awsCloudFormationNode|awsCloudWatchLogNode|awsS3BucketNode|awsS3FolderNode|awsS3FileNode|awsApiGatewayNode|awsEcrRepositoryNode|awsIotThingNode)$|^(awsAppRunnerServiceNode|awsEcsServiceNode|awsIotCertificateNode|awsIotPolicyNode|awsIotPolicyVersionNode|awsMdeInstanceNode|awsEc2Node)/",
16101615
"group": "2@2"
16111616
},
16121617
{
@@ -2087,6 +2092,16 @@
20872092
}
20882093
}
20892094
},
2095+
{
2096+
"command": "aws.ec2.copyInstanceId",
2097+
"title": "%AWS.command.ec2.copyInstanceId%",
2098+
"category": "%AWS.title",
2099+
"cloud9": {
2100+
"cn": {
2101+
"category": "%AWS.title.cn%"
2102+
}
2103+
}
2104+
},
20902105
{
20912106
"command": "aws.ecr.copyTagUri",
20922107
"title": "%AWS.command.ecr.copyTagUri%",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"AWS.command.cdk.help": "View CDK Documentation",
111111
"AWS.command.ec2.openTerminal": "Open terminal to EC2 instance...",
112112
"AWS.command.ec2.openRemoteConnection": "Connect to EC2 instance in New Window...",
113+
"AWS.command.ec2.copyInstanceId": "Copy Instance Id",
113114
"AWS.command.ecr.copyTagUri": "Copy Tag URI",
114115
"AWS.command.ecr.copyRepositoryUri": "Copy Repository URI",
115116
"AWS.command.ecr.createRepository": "Create Repository...",

src/awsexplorer/activation.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import { downloadStateMachineDefinition } from '../stepFunctions/commands/downlo
1919
import { executeStateMachine } from '../stepFunctions/vue/executeStateMachine/executeStateMachine'
2020
import { StateMachineNode } from '../stepFunctions/explorer/stepFunctionsNodes'
2121
import { AwsExplorer } from './awsExplorer'
22-
import { copyArnCommand } from './commands/copyArn'
23-
import { copyNameCommand } from './commands/copyName'
22+
import { copyTextCommand } from './commands/copyText'
2423
import { loadMoreChildrenCommand } from './commands/loadMoreChildren'
2524
import { checkExplorerForDefaultRegion } from './defaultRegion'
2625
import { createLocalExplorerView } from './localExplorer'
@@ -156,8 +155,8 @@ async function registerAwsExplorerCommands(
156155
isPreviewAndRender: true,
157156
})
158157
),
159-
Commands.register('aws.copyArn', async (node: AWSResourceNode) => await copyArnCommand(node)),
160-
Commands.register('aws.copyName', async (node: AWSResourceNode) => await copyNameCommand(node)),
158+
Commands.register('aws.copyArn', async (node: AWSResourceNode) => await copyTextCommand(node, 'ARN')),
159+
Commands.register('aws.copyName', async (node: AWSResourceNode) => await copyTextCommand(node, 'name')),
161160
Commands.register('aws.refreshAwsExplorerNode', async (element: AWSTreeNodeBase | undefined) => {
162161
awsExplorer.refresh(element)
163162
}),

src/awsexplorer/commands/copyArn.ts

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

src/awsexplorer/commands/copyName.ts renamed to src/awsexplorer/commands/copyText.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,23 @@ import { copyToClipboard } from '../../shared/utilities/messages'
88
import { AWSResourceNode } from '../../shared/treeview/nodes/awsResourceNode'
99
import { TreeShim } from '../../shared/treeview/utils'
1010

11-
/**
12-
* Copies the name of the resource represented by the given node.
13-
*/
14-
export async function copyNameCommand(
11+
export type copyableText = 'ARN' | 'name' | 'id'
12+
13+
export async function copyTextCommand(
1514
node: AWSResourceNode | TreeShim<AWSResourceNode>,
15+
text: copyableText,
1616
env = Env.vscode()
1717
): Promise<void> {
1818
node = node instanceof TreeShim ? node.node.resource : node
19-
20-
await copyToClipboard(node.name, 'name', env)
19+
switch (text) {
20+
case 'ARN':
21+
await copyToClipboard(node.arn, text, env)
22+
break
23+
case 'name':
24+
await copyToClipboard(node.name, text, env)
25+
break
26+
case 'id':
27+
await copyToClipboard(node.id!, text, env)
28+
break
29+
}
2130
}

src/ec2/activation.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import { ExtContext } from '../shared/extensions'
66
import { Commands } from '../shared/vscode/commands2'
77
import { telemetry } from '../shared/telemetry/telemetry'
8+
import { Ec2InstanceNode } from './explorer/ec2InstanceNode'
9+
import { copyTextCommand } from '../awsexplorer/commands/copyText'
810
import { Ec2Node } from './explorer/ec2ParentNode'
911
import { openRemoteConnection, openTerminal } from './commands'
1012

@@ -17,6 +19,9 @@ export async function activate(ctx: ExtContext): Promise<void> {
1719
})
1820
}),
1921

22+
Commands.register('aws.ec2.copyInstanceId', async (node: Ec2InstanceNode) => {
23+
await copyTextCommand(node, 'id')
24+
}),
2025
Commands.register('aws.ec2.openRemoteConnection', async (node?: Ec2Node) => {
2126
await (node ? openRemoteConnection(node) : openRemoteConnection(node))
2227
})

src/ec2/commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { Ec2InstanceNode } from './explorer/ec2InstanceNode'
77
import { Ec2Node } from './explorer/ec2ParentNode'
88
import { Ec2ConnectionManager } from './model'
9+
import { copyToClipboard } from '../shared/utilities/messages'
910
import { promptUserForEc2Selection } from './prompter'
1011

1112
export async function openTerminal(node?: Ec2Node) {
@@ -20,3 +21,7 @@ export async function openRemoteConnection(node?: Ec2Node) {
2021
//const connectionManager = new Ec2ConnectionManager(selection.region)
2122
console.log(selection)
2223
}
24+
25+
export async function copyInstanceId(instanceId: string): Promise<void> {
26+
await copyToClipboard(instanceId, 'Id')
27+
}

src/ec2/explorer/ec2InstanceNode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class Ec2InstanceNode extends AWSTreeNodeBase implements AWSResourceNode
1919
) {
2020
super('')
2121
this.update(instance)
22+
this.id = this.InstanceId
2223
}
2324

2425
public update(newInstance: Ec2Instance) {

src/shared/treeview/nodes/awsResourceNode.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ export interface AWSResourceNode {
1313
* Returns the name of the AWS resource.
1414
*/
1515
readonly name: string
16+
17+
/** Service-defined idenifier, e.g. for EC2 this is the "Instance Id". */
18+
readonly id?: string
1619
}

src/test/awsExplorer/commands/copyArn.test.ts

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

0 commit comments

Comments
 (0)