Skip to content

Commit 2c0b4a5

Browse files
authored
deps(apigateway): migrate client to use v3. (aws#6760)
## Problem client still uses v2. ## Solution - Very straightforward migration, mostly exchanging types. ## Verification - Create a simple APIGateway that redirects to a GET request to this repo's homepage. - Use the invoke method from the IDE. - Copy ARN, name, and URL. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent f4f9354 commit 2c0b4a5

File tree

8 files changed

+633
-92
lines changed

8 files changed

+633
-92
lines changed

package-lock.json

Lines changed: 540 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@
504504
"@aws-sdk/client-ec2": "<3.696.0",
505505
"@aws-sdk/client-iam": "<3.696.0",
506506
"@aws-sdk/client-s3": "<3.696.0",
507+
"@aws-sdk/client-api-gateway": "<3.696.0",
507508
"@aws-sdk/lib-storage": "<3.696.0",
508509
"@aws-sdk/client-lambda": "<3.696.0",
509510
"@aws-sdk/client-ssm": "<3.696.0",

packages/core/src/awsService/apigateway/commands/copyUrl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as vscode from 'vscode'
1212
import { ProgressLocation } from 'vscode'
1313

1414
import { Stage } from 'aws-sdk/clients/apigateway'
15-
import { DefaultApiGatewayClient } from '../../../shared/clients/apiGatewayClient'
15+
import { ApiGatewayClient } from '../../../shared/clients/apiGateway'
1616
import { defaultDnsSuffix, RegionProvider } from '../../../shared/regions/regionProvider'
1717
import { getLogger } from '../../../shared/logger/logger'
1818
import { telemetry } from '../../../shared/telemetry/telemetry'
@@ -25,7 +25,7 @@ interface StageInvokeUrlQuickPick extends vscode.QuickPickItem {
2525
export async function copyUrlCommand(node: RestApiNode, regionProvider: RegionProvider): Promise<void> {
2626
const region = node.regionCode
2727
const dnsSuffix = regionProvider.getDnsSuffixForRegion(region) || defaultDnsSuffix
28-
const client = new DefaultApiGatewayClient(region)
28+
const client = new ApiGatewayClient(region)
2929

3030
let stages: Stage[]
3131
try {

packages/core/src/awsService/apigateway/explorer/apiGatewayNodes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as vscode from 'vscode'
1111
import { AWSTreeNodeBase } from '../../../shared/treeview/nodes/awsTreeNodeBase'
1212
import { PlaceholderNode } from '../../../shared/treeview/nodes/placeholderNode'
1313
import { compareTreeItems, makeChildrenNodes } from '../../../shared/treeview/utils'
14-
import { DefaultApiGatewayClient } from '../../../shared/clients/apiGatewayClient'
14+
import { ApiGatewayClient } from '../../../shared/clients/apiGateway'
1515
import { RestApi } from 'aws-sdk/clients/apigateway'
1616
import { toArrayAsync, toMap, updateInPlace } from '../../../shared/utilities/collectionUtils'
1717
import { RestApiNode } from './apiNodes'
@@ -25,7 +25,7 @@ export class ApiGatewayNode extends AWSTreeNodeBase {
2525
public constructor(
2626
private readonly partitionId: string,
2727
public override readonly regionCode: string,
28-
private readonly client = new DefaultApiGatewayClient(regionCode)
28+
private readonly client = new ApiGatewayClient(regionCode)
2929
) {
3030
super('API Gateway', vscode.TreeItemCollapsibleState.Collapsed)
3131
this.apiNodes = new Map<string, RestApiNode>()

packages/core/src/awsService/apigateway/vue/invokeRemoteRestApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { localize } from '../../../shared/utilities/vsCodeUtils'
1313
import { Result } from '../../../shared/telemetry/telemetry'
1414
import { VueWebview } from '../../../webviews/main'
1515
import { ExtContext } from '../../../shared/extensions'
16-
import { DefaultApiGatewayClient } from '../../../shared/clients/apiGatewayClient'
16+
import { ApiGatewayClient } from '../../../shared/clients/apiGateway'
1717
import { telemetry } from '../../../shared/telemetry/telemetry'
1818

1919
interface InvokeApiMessage {
@@ -50,7 +50,7 @@ export class RemoteRestInvokeWebview extends VueWebview {
5050
public constructor(
5151
private readonly data: InvokeRemoteRestApiInitialData,
5252
private readonly channel: vscode.OutputChannel,
53-
private readonly client = new DefaultApiGatewayClient(data.Region)
53+
private readonly client = new ApiGatewayClient(data.Region)
5454
) {
5555
super(RemoteRestInvokeWebview.sourcePath)
5656
}
@@ -115,7 +115,7 @@ export async function invokeRemoteRestApi(
115115
const logger: Logger = getLogger()
116116

117117
try {
118-
const client = new DefaultApiGatewayClient(params.apiNode.regionCode)
118+
const client = new ApiGatewayClient(params.apiNode.regionCode)
119119
logger.info(`Loading API Resources for API ${params.apiNode.name} (id: ${params.apiNode.id})`)
120120
const resources = (await toArrayAsync(client.getResourcesForApi(params.apiNode.id)))
121121
.sort((a, b) => a.path!.localeCompare(b.path!))
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import { ClientWrapper } from './clientWrapper'
6+
import {
7+
APIGatewayClient as ApiGatewayClientSDK,
8+
GetResourcesCommand,
9+
GetResourcesRequest,
10+
GetRestApisCommand,
11+
GetRestApisRequest,
12+
GetStagesCommand,
13+
Resource,
14+
Resources,
15+
RestApi,
16+
RestApis,
17+
Stages,
18+
TestInvokeMethodCommand,
19+
TestInvokeMethodRequest,
20+
TestInvokeMethodResponse,
21+
} from '@aws-sdk/client-api-gateway'
22+
23+
export class ApiGatewayClient extends ClientWrapper<ApiGatewayClientSDK> {
24+
public constructor(regionCode: string) {
25+
super(regionCode, ApiGatewayClientSDK)
26+
}
27+
28+
public async *getResourcesForApi(apiId: string): AsyncIterableIterator<Resource> {
29+
const request: GetResourcesRequest = {
30+
restApiId: apiId,
31+
}
32+
33+
do {
34+
const response: Resources = await this.makeRequest(GetResourcesCommand, request)
35+
36+
if (response.items !== undefined && response.items.length > 0) {
37+
yield* response.items
38+
}
39+
40+
request.position = response.position
41+
} while (request.position !== undefined)
42+
}
43+
44+
public async getStages(apiId: string): Promise<Stages> {
45+
return this.makeRequest(GetStagesCommand, {
46+
restApiId: apiId,
47+
})
48+
}
49+
50+
public async *listApis(): AsyncIterableIterator<RestApi> {
51+
const request: GetRestApisRequest = {}
52+
53+
do {
54+
const response: RestApis = await this.makeRequest(GetRestApisCommand, request)
55+
56+
if (response.items !== undefined && response.items.length > 0) {
57+
yield* response.items
58+
}
59+
60+
request.position = response.position
61+
} while (request.position !== undefined)
62+
}
63+
64+
public async testInvokeMethod(
65+
apiId: string,
66+
resourceId: string,
67+
method: string,
68+
body: string,
69+
pathWithQueryString: string | undefined
70+
): Promise<TestInvokeMethodResponse> {
71+
const request: TestInvokeMethodRequest = {
72+
restApiId: apiId,
73+
resourceId: resourceId,
74+
httpMethod: method,
75+
body: body,
76+
}
77+
if (pathWithQueryString) {
78+
request.pathWithQueryString = pathWithQueryString
79+
}
80+
81+
return this.makeRequest(TestInvokeMethodCommand, request)
82+
}
83+
}

packages/core/src/shared/clients/apiGatewayClient.ts

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

packages/core/src/test/awsService/apigateway/explorer/apiGatewayNodes.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { asyncGenerator } from '../../../../shared/utilities/collectionUtils'
1212
import { ApiGatewayNode } from '../../../../awsService/apigateway/explorer/apiGatewayNodes'
1313
import { RestApiNode } from '../../../../awsService/apigateway/explorer/apiNodes'
14-
import { DefaultApiGatewayClient } from '../../../../shared/clients/apiGatewayClient'
14+
import { ApiGatewayClient } from '../../../../shared/clients/apiGateway'
1515
import { stub } from '../../../utilities/stubber'
1616

1717
const fakePartitionId = 'aws'
@@ -37,7 +37,7 @@ describe('ApiGatewayNode', function () {
3737
let apiNames: { name: string; id: string }[]
3838

3939
function createClient() {
40-
const client = stub(DefaultApiGatewayClient, { regionCode: fakeRegionCode })
40+
const client = stub(ApiGatewayClient, { regionCode: fakeRegionCode })
4141
client.listApis.callsFake(() => asyncGenerator(apiNames))
4242

4343
return client

0 commit comments

Comments
 (0)