Skip to content

Commit

Permalink
feat: open AWS console for AWS::SQS::Queue (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
fossamagna authored Aug 10, 2024
1 parent f91eb58 commit aaf5914
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-geckos-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"amplify-backend-vscode": minor
---

feat: open AWS console for `AWS::SQS::Queue`
18 changes: 18 additions & 0 deletions src/console-url-builder/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,22 @@ describe("Console URL Builder Test Suite", () => {
"https://ap-northeast-1.console.aws.amazon.com/appsync/home?region=ap-northeast-1#/0123456789abcdefghijklmnop/v1/schema"
);
});

test("AWS::SQS::Queue", () => {
const url = buildUrl({
ResourceType: "AWS::SQS::Queue",
StackId:
"arn:aws:cloudformation:ap-northeast-1:123456789012:stack/myteststack/abc",
PhysicalResourceId:
"https://sqs.ap-northeast-1.amazonaws.com/123456789012/test-queue-name.fifo",
});
assert.deepEqual(url, {
scheme: "https",
authority: "ap-northeast-1.console.aws.amazon.com",
path: "/sqs/v3/home",
query: "region=ap-northeast-1",
fragment:
"/queues/https%3A%2F%2Fsqs.ap-northeast-1.amazonaws.com%2F123456789012%2Ftest-queue-name.fifo",
});
});
});
35 changes: 34 additions & 1 deletion src/console-url-builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,32 @@ export function buildUrl(
}
}

export type UriComponents = {
/**
* The scheme of the uri
*/
readonly scheme: string;
/**
* The authority of the uri
*/
readonly authority?: string;
/**
* The path of the uri
*/
readonly path?: string;
/**
* The query string of the uri
*/
readonly query?: string;
/**
* The fragment identifier of the uri
*/
readonly fragment?: string;
};

const urlBuilders: Record<
string,
(physicalResourceId: string, region: string) => string
(physicalResourceId: string, region: string) => string | UriComponents
> = {
"AWS::CloudFormation::Stack": (physicalResourceId, region) => {
const resourceId = physicalResourceId!;
Expand Down Expand Up @@ -76,4 +99,14 @@ const urlBuilders: Record<
const tableName = physicalResourceId;
return `https://${region}.console.aws.amazon.com/dynamodbv2/home?region=${region}#table?name=${tableName}&tab=overview`;
},
"AWS::SQS::Queue": (physicalResourceId, region) => {
const resourceId = physicalResourceId;
return {
scheme: "https",
authority: `${region}.console.aws.amazon.com`,
path: `/sqs/v3/home`,
query: `region=${region}`,
fragment: `/queues/${encodeURIComponent(resourceId)}`,
};
},
};
4 changes: 2 additions & 2 deletions src/explorer/amplify-backend-resource-tree-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from "vscode";
import { StackResource } from "@aws-sdk/client-cloudformation";
import { AmplifyBackendBaseNode } from "./amplify-backend-base-node";
import { isStack } from "./utils";
import { buildUrl } from "../console-url-builder";
import { buildUrl, UriComponents } from "../console-url-builder";
import type { BackendIdentifier } from "@aws-amplify/plugin-types";

export class AmplifyBackendResourceTreeNode extends AmplifyBackendBaseNode {
Expand All @@ -26,7 +26,7 @@ export class AmplifyBackendResourceTreeNode extends AmplifyBackendBaseNode {
this.contextValue = "resourceNode";
}

get consoleUrl(): string | undefined {
get consoleUrl(): string | UriComponents | undefined {
return this.resource && buildUrl(this.resource);
}
}
10 changes: 7 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand(
"amplify-backend-explorer.openConsole",
(node: AmplifyBackendResourceTreeNode) => {
const url = node.consoleUrl;
if (url) {
vscode.env.openExternal(vscode.Uri.parse(url));
const { consoleUrl } = node;
if (consoleUrl) {
const uri =
typeof consoleUrl === "string"
? vscode.Uri.parse(consoleUrl)
: vscode.Uri.from(consoleUrl);
vscode.env.openExternal(uri);
} else {
vscode.window.showInformationMessage(
`Now ${node.cloudformationType} is not supported resource type to open AWS Cosnsole.`
Expand Down

0 comments on commit aaf5914

Please sign in to comment.