Skip to content

Commit

Permalink
deps(apigateway): migrate client to use v3. (#6760)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
Hweinstock authored Mar 11, 2025
1 parent f4f9354 commit 2c0b4a5
Show file tree
Hide file tree
Showing 8 changed files with 633 additions and 92 deletions.
540 changes: 540 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@
"@aws-sdk/client-ec2": "<3.696.0",
"@aws-sdk/client-iam": "<3.696.0",
"@aws-sdk/client-s3": "<3.696.0",
"@aws-sdk/client-api-gateway": "<3.696.0",
"@aws-sdk/lib-storage": "<3.696.0",
"@aws-sdk/client-lambda": "<3.696.0",
"@aws-sdk/client-ssm": "<3.696.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/awsService/apigateway/commands/copyUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as vscode from 'vscode'
import { ProgressLocation } from 'vscode'

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

let stages: Stage[]
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as vscode from 'vscode'
import { AWSTreeNodeBase } from '../../../shared/treeview/nodes/awsTreeNodeBase'
import { PlaceholderNode } from '../../../shared/treeview/nodes/placeholderNode'
import { compareTreeItems, makeChildrenNodes } from '../../../shared/treeview/utils'
import { DefaultApiGatewayClient } from '../../../shared/clients/apiGatewayClient'
import { ApiGatewayClient } from '../../../shared/clients/apiGateway'
import { RestApi } from 'aws-sdk/clients/apigateway'
import { toArrayAsync, toMap, updateInPlace } from '../../../shared/utilities/collectionUtils'
import { RestApiNode } from './apiNodes'
Expand All @@ -25,7 +25,7 @@ export class ApiGatewayNode extends AWSTreeNodeBase {
public constructor(
private readonly partitionId: string,
public override readonly regionCode: string,
private readonly client = new DefaultApiGatewayClient(regionCode)
private readonly client = new ApiGatewayClient(regionCode)
) {
super('API Gateway', vscode.TreeItemCollapsibleState.Collapsed)
this.apiNodes = new Map<string, RestApiNode>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { localize } from '../../../shared/utilities/vsCodeUtils'
import { Result } from '../../../shared/telemetry/telemetry'
import { VueWebview } from '../../../webviews/main'
import { ExtContext } from '../../../shared/extensions'
import { DefaultApiGatewayClient } from '../../../shared/clients/apiGatewayClient'
import { ApiGatewayClient } from '../../../shared/clients/apiGateway'
import { telemetry } from '../../../shared/telemetry/telemetry'

interface InvokeApiMessage {
Expand Down Expand Up @@ -50,7 +50,7 @@ export class RemoteRestInvokeWebview extends VueWebview {
public constructor(
private readonly data: InvokeRemoteRestApiInitialData,
private readonly channel: vscode.OutputChannel,
private readonly client = new DefaultApiGatewayClient(data.Region)
private readonly client = new ApiGatewayClient(data.Region)
) {
super(RemoteRestInvokeWebview.sourcePath)
}
Expand Down Expand Up @@ -115,7 +115,7 @@ export async function invokeRemoteRestApi(
const logger: Logger = getLogger()

try {
const client = new DefaultApiGatewayClient(params.apiNode.regionCode)
const client = new ApiGatewayClient(params.apiNode.regionCode)
logger.info(`Loading API Resources for API ${params.apiNode.name} (id: ${params.apiNode.id})`)
const resources = (await toArrayAsync(client.getResourcesForApi(params.apiNode.id)))
.sort((a, b) => a.path!.localeCompare(b.path!))
Expand Down
83 changes: 83 additions & 0 deletions packages/core/src/shared/clients/apiGateway.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import { ClientWrapper } from './clientWrapper'
import {
APIGatewayClient as ApiGatewayClientSDK,
GetResourcesCommand,
GetResourcesRequest,
GetRestApisCommand,
GetRestApisRequest,
GetStagesCommand,
Resource,
Resources,
RestApi,
RestApis,
Stages,
TestInvokeMethodCommand,
TestInvokeMethodRequest,
TestInvokeMethodResponse,
} from '@aws-sdk/client-api-gateway'

export class ApiGatewayClient extends ClientWrapper<ApiGatewayClientSDK> {
public constructor(regionCode: string) {
super(regionCode, ApiGatewayClientSDK)
}

public async *getResourcesForApi(apiId: string): AsyncIterableIterator<Resource> {
const request: GetResourcesRequest = {
restApiId: apiId,
}

do {
const response: Resources = await this.makeRequest(GetResourcesCommand, request)

if (response.items !== undefined && response.items.length > 0) {
yield* response.items
}

request.position = response.position
} while (request.position !== undefined)
}

public async getStages(apiId: string): Promise<Stages> {
return this.makeRequest(GetStagesCommand, {
restApiId: apiId,
})
}

public async *listApis(): AsyncIterableIterator<RestApi> {
const request: GetRestApisRequest = {}

do {
const response: RestApis = await this.makeRequest(GetRestApisCommand, request)

if (response.items !== undefined && response.items.length > 0) {
yield* response.items
}

request.position = response.position
} while (request.position !== undefined)
}

public async testInvokeMethod(
apiId: string,
resourceId: string,
method: string,
body: string,
pathWithQueryString: string | undefined
): Promise<TestInvokeMethodResponse> {
const request: TestInvokeMethodRequest = {
restApiId: apiId,
resourceId: resourceId,
httpMethod: method,
body: body,
}
if (pathWithQueryString) {
request.pathWithQueryString = pathWithQueryString
}

return this.makeRequest(TestInvokeMethodCommand, request)
}
}
83 changes: 0 additions & 83 deletions packages/core/src/shared/clients/apiGatewayClient.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { asyncGenerator } from '../../../../shared/utilities/collectionUtils'
import { ApiGatewayNode } from '../../../../awsService/apigateway/explorer/apiGatewayNodes'
import { RestApiNode } from '../../../../awsService/apigateway/explorer/apiNodes'
import { DefaultApiGatewayClient } from '../../../../shared/clients/apiGatewayClient'
import { ApiGatewayClient } from '../../../../shared/clients/apiGateway'
import { stub } from '../../../utilities/stubber'

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

function createClient() {
const client = stub(DefaultApiGatewayClient, { regionCode: fakeRegionCode })
const client = stub(ApiGatewayClient, { regionCode: fakeRegionCode })
client.listApis.callsFake(() => asyncGenerator(apiNames))

return client
Expand Down

0 comments on commit 2c0b4a5

Please sign in to comment.