|
| 1 | +/*! |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | +import { Ec2InstanceNode } from './explorer/ec2InstanceNode' |
| 6 | +import { Ec2Node } from './explorer/ec2ParentNode' |
| 7 | +import { Ec2Prompter, instanceFilter, Ec2Selection } from './prompter' |
| 8 | +import { copyToClipboard } from '../../shared/utilities/messages' |
| 9 | +import { getLogger } from '../../shared/logger' |
| 10 | +import { ec2LogSchema } from './ec2LogDocumentProvider' |
| 11 | +import { getAwsConsoleUrl } from '../../shared/awsConsole' |
| 12 | +import { showRegionPrompter } from '../../auth/utils' |
| 13 | +import { openUrl } from '../../shared/utilities/vsCodeUtils' |
| 14 | +import { showFile } from '../../shared/utilities/textDocumentUtilities' |
| 15 | + |
| 16 | +export function refreshExplorer(node?: Ec2Node) { |
| 17 | + if (node) { |
| 18 | + const n = node instanceof Ec2InstanceNode ? node.parent : node |
| 19 | + n.refreshNode().catch((e) => { |
| 20 | + getLogger().error('refreshNode failed: %s', (e as Error).message) |
| 21 | + }) |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +export async function linkToLaunchInstance(node?: Ec2Node) { |
| 26 | + const region = node ? node.regionCode : (await showRegionPrompter('Select Region', '')).id |
| 27 | + const url = getAwsConsoleUrl('ec2-launch', region) |
| 28 | + await openUrl(url) |
| 29 | +} |
| 30 | + |
| 31 | +async function getSelection(node?: Ec2Node, filter?: instanceFilter): Promise<Ec2Selection> { |
| 32 | + const prompter = new Ec2Prompter(filter) |
| 33 | + const selection = node && node instanceof Ec2InstanceNode ? node.toSelection() : await prompter.promptUser() |
| 34 | + return selection |
| 35 | +} |
| 36 | + |
| 37 | +export async function copyInstanceId(instanceId: string): Promise<void> { |
| 38 | + await copyToClipboard(instanceId, 'Id') |
| 39 | +} |
| 40 | + |
| 41 | +export async function openLogDocument(node?: Ec2InstanceNode): Promise<void> { |
| 42 | + return await showFile(ec2LogSchema.form(await getSelection(node))) |
| 43 | +} |
0 commit comments