Skip to content

Commit 00abff1

Browse files
authored
refactor(schemas): migrate to aws-sdk v3 (aws#8056)
## Problem AWS SDK V2 is at EOL. ## Solution Migrate Schemas client to V3 --- - 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 665d5a8 commit 00abff1

File tree

7 files changed

+1158
-220
lines changed

7 files changed

+1158
-220
lines changed

package-lock.json

Lines changed: 1058 additions & 149 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
@@ -587,6 +587,7 @@
587587
"@aws-sdk/client-s3": "<3.731.0",
588588
"@aws-sdk/client-s3-control": "^3.830.0",
589589
"@aws-sdk/client-sagemaker": "<3.696.0",
590+
"@aws-sdk/client-schemas": "~3.693.0",
590591
"@aws-sdk/client-sfn": "<3.731.0",
591592
"@aws-sdk/client-ssm": "<3.731.0",
592593
"@aws-sdk/client-sso": "<3.731.0",

packages/core/src/eventSchemas/commands/downloadSchemaItemCode.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as nls from 'vscode-nls'
77
const localize = nls.loadMessageBundle()
8-
import { Schemas } from 'aws-sdk'
8+
import { PutCodeBindingResponse } from '@aws-sdk/client-schemas'
99
import fs = require('fs')
1010
import path = require('path')
1111
import * as vscode from 'vscode'
@@ -180,10 +180,8 @@ export class SchemaCodeDownloader {
180180
export class CodeGenerator {
181181
public constructor(public client: SchemaClient) {}
182182

183-
public async generate(
184-
codeDownloadRequest: SchemaCodeDownloadRequestDetails
185-
): Promise<Schemas.PutCodeBindingResponse> {
186-
let response: Schemas.PutCodeBindingResponse
183+
public async generate(codeDownloadRequest: SchemaCodeDownloadRequestDetails): Promise<PutCodeBindingResponse> {
184+
let response: PutCodeBindingResponse
187185
try {
188186
response = await this.client.putCodeBinding(
189187
codeDownloadRequest.language,

packages/core/src/eventSchemas/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import * as nls from 'vscode-nls'
77
const localize = nls.loadMessageBundle()
88

9-
import { Schemas } from 'aws-sdk'
9+
import { RegistrySummary, SchemaSummary, SearchSchemaSummary } from '@aws-sdk/client-schemas'
1010
import * as vscode from 'vscode'
1111
import { SchemaClient } from '../shared/clients/schemaClient'
1212

13-
export async function* listRegistryItems(client: SchemaClient): AsyncIterableIterator<Schemas.RegistrySummary> {
13+
export async function* listRegistryItems(client: SchemaClient): AsyncIterableIterator<RegistrySummary> {
1414
const status = vscode.window.setStatusBarMessage(
1515
localize('AWS.message.statusBar.loading.registries', 'Loading Registry Items...')
1616
)
@@ -25,7 +25,7 @@ export async function* listRegistryItems(client: SchemaClient): AsyncIterableIte
2525
export async function* listSchemaItems(
2626
client: SchemaClient,
2727
registryName: string
28-
): AsyncIterableIterator<Schemas.SchemaSummary> {
28+
): AsyncIterableIterator<SchemaSummary> {
2929
const status = vscode.window.setStatusBarMessage(
3030
localize('AWS.message.statusBar.loading.schemaItems', 'Loading Schema Items...')
3131
)
@@ -41,7 +41,7 @@ export async function* searchSchemas(
4141
client: SchemaClient,
4242
keyword: string,
4343
registryName: string
44-
): AsyncIterableIterator<Schemas.SearchSchemaSummary> {
44+
): AsyncIterableIterator<SearchSchemaSummary> {
4545
const status = vscode.window.setStatusBarMessage(
4646
localize('AWS.message.statusBar.searching.schemas', 'Searching Schemas...')
4747
)

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

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,33 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { Schemas } from 'aws-sdk'
6+
import {
7+
DescribeCodeBindingCommand,
8+
DescribeCodeBindingResponse,
9+
DescribeSchemaCommand,
10+
DescribeSchemaResponse,
11+
GetCodeBindingSourceCommand,
12+
GetCodeBindingSourceResponse,
13+
ListRegistriesCommand,
14+
ListRegistriesRequest,
15+
ListRegistriesResponse,
16+
ListSchemasCommand,
17+
ListSchemasRequest,
18+
ListSchemasResponse,
19+
ListSchemaVersionsCommand,
20+
ListSchemaVersionsRequest,
21+
ListSchemaVersionsResponse,
22+
PutCodeBindingCommand,
23+
PutCodeBindingResponse,
24+
RegistrySummary,
25+
SchemasClient,
26+
SchemaSummary,
27+
SchemaVersionSummary,
28+
SearchSchemasCommand,
29+
SearchSchemasRequest,
30+
SearchSchemasResponse,
31+
SearchSchemaSummary,
32+
} from '@aws-sdk/client-schemas'
733
import globals from '../extensionGlobals'
834

935
import { ClassToInterfaceType } from '../utilities/tsUtils'
@@ -12,13 +38,13 @@ export type SchemaClient = ClassToInterfaceType<DefaultSchemaClient>
1238
export class DefaultSchemaClient {
1339
public constructor(public readonly regionCode: string) {}
1440

15-
public async *listRegistries(): AsyncIterableIterator<Schemas.RegistrySummary> {
16-
const client = await this.createSdkClient()
41+
public async *listRegistries(): AsyncIterableIterator<RegistrySummary> {
42+
const client = this.createSdkClient()
1743

18-
const request: Schemas.ListRegistriesRequest = {}
44+
const request: ListRegistriesRequest = {}
1945

2046
do {
21-
const response: Schemas.ListRegistriesResponse = await client.listRegistries(request).promise()
47+
const response: ListRegistriesResponse = await client.send(new ListRegistriesCommand(request))
2248

2349
if (response.Registries) {
2450
yield* response.Registries
@@ -28,15 +54,15 @@ export class DefaultSchemaClient {
2854
} while (request.NextToken)
2955
}
3056

31-
public async *listSchemas(registryName: string): AsyncIterableIterator<Schemas.SchemaSummary> {
32-
const client = await this.createSdkClient()
57+
public async *listSchemas(registryName: string): AsyncIterableIterator<SchemaSummary> {
58+
const client = this.createSdkClient()
3359

34-
const request: Schemas.ListSchemasRequest = {
60+
const request: ListSchemasRequest = {
3561
RegistryName: registryName,
3662
}
3763

3864
do {
39-
const response: Schemas.ListSchemasResponse = await client.listSchemas(request).promise()
65+
const response: ListSchemasResponse = await client.send(new ListSchemasCommand(request))
4066

4167
if (response.Schemas) {
4268
yield* response.Schemas
@@ -50,31 +76,31 @@ export class DefaultSchemaClient {
5076
registryName: string,
5177
schemaName: string,
5278
schemaVersion?: string
53-
): Promise<Schemas.DescribeSchemaResponse> {
54-
const client = await this.createSdkClient()
79+
): Promise<DescribeSchemaResponse> {
80+
const client = this.createSdkClient()
5581

56-
return await client
57-
.describeSchema({
82+
return await client.send(
83+
new DescribeSchemaCommand({
5884
RegistryName: registryName,
5985
SchemaName: schemaName,
6086
SchemaVersion: schemaVersion,
6187
})
62-
.promise()
88+
)
6389
}
6490

6591
public async *listSchemaVersions(
6692
registryName: string,
6793
schemaName: string
68-
): AsyncIterableIterator<Schemas.SchemaVersionSummary> {
69-
const client = await this.createSdkClient()
94+
): AsyncIterableIterator<SchemaVersionSummary> {
95+
const client = this.createSdkClient()
7096

71-
const request: Schemas.ListSchemaVersionsRequest = {
97+
const request: ListSchemaVersionsRequest = {
7298
RegistryName: registryName,
7399
SchemaName: schemaName,
74100
}
75101

76102
do {
77-
const response: Schemas.ListSchemaVersionsResponse = await client.listSchemaVersions(request).promise()
103+
const response: ListSchemaVersionsResponse = await client.send(new ListSchemaVersionsCommand(request))
78104

79105
if (response.SchemaVersions) {
80106
yield* response.SchemaVersions
@@ -84,19 +110,16 @@ export class DefaultSchemaClient {
84110
} while (request.NextToken)
85111
}
86112

87-
public async *searchSchemas(
88-
keywords: string,
89-
registryName: string
90-
): AsyncIterableIterator<Schemas.SearchSchemaSummary> {
91-
const client = await this.createSdkClient()
113+
public async *searchSchemas(keywords: string, registryName: string): AsyncIterableIterator<SearchSchemaSummary> {
114+
const client = this.createSdkClient()
92115

93-
const request: Schemas.SearchSchemasRequest = {
116+
const request: SearchSchemasRequest = {
94117
Keywords: keywords,
95118
RegistryName: registryName,
96119
}
97120

98121
do {
99-
const response: Schemas.SearchSchemasResponse = await client.searchSchemas(request).promise()
122+
const response: SearchSchemasResponse = await client.send(new SearchSchemasCommand(request))
100123

101124
if (response.Schemas) {
102125
yield* response.Schemas
@@ -111,55 +134,58 @@ export class DefaultSchemaClient {
111134
registryName: string,
112135
schemaName: string,
113136
schemaVersion: string
114-
): Promise<Schemas.GetCodeBindingSourceResponse> {
115-
const client = await this.createSdkClient()
137+
): Promise<GetCodeBindingSourceResponse> {
138+
const client = this.createSdkClient()
116139

117-
return await client
118-
.getCodeBindingSource({
140+
return await client.send(
141+
new GetCodeBindingSourceCommand({
119142
Language: language,
120143
RegistryName: registryName,
121144
SchemaName: schemaName,
122145
SchemaVersion: schemaVersion,
123146
})
124-
.promise()
147+
)
125148
}
126149

127150
public async putCodeBinding(
128151
language: string,
129152
registryName: string,
130153
schemaName: string,
131154
schemaVersion: string
132-
): Promise<Schemas.PutCodeBindingResponse> {
133-
const client = await this.createSdkClient()
155+
): Promise<PutCodeBindingResponse> {
156+
const client = this.createSdkClient()
134157

135-
return await client
136-
.putCodeBinding({
158+
return await client.send(
159+
new PutCodeBindingCommand({
137160
Language: language,
138161
RegistryName: registryName,
139162
SchemaName: schemaName,
140163
SchemaVersion: schemaVersion,
141164
})
142-
.promise()
165+
)
143166
}
144167
public async describeCodeBinding(
145168
language: string,
146169
registryName: string,
147170
schemaName: string,
148171
schemaVersion: string
149-
): Promise<Schemas.DescribeCodeBindingResponse> {
150-
const client = await this.createSdkClient()
172+
): Promise<DescribeCodeBindingResponse> {
173+
const client = this.createSdkClient()
151174

152-
return await client
153-
.describeCodeBinding({
175+
return await client.send(
176+
new DescribeCodeBindingCommand({
154177
Language: language,
155178
RegistryName: registryName,
156179
SchemaName: schemaName,
157180
SchemaVersion: schemaVersion,
158181
})
159-
.promise()
182+
)
160183
}
161184

162-
private async createSdkClient(): Promise<Schemas> {
163-
return await globals.sdkClientBuilder.createAwsService(Schemas, undefined, this.regionCode)
185+
private createSdkClient(): SchemasClient {
186+
return globals.sdkClientBuilderV3.createAwsService({
187+
serviceClient: SchemasClient,
188+
clientOptions: { region: this.regionCode },
189+
})
164190
}
165191
}

packages/core/src/test/eventSchemas/commands/downloadSchemaItemCode.test.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import assert from 'assert'
77
import * as path from 'path'
88
import * as vscode from 'vscode'
99

10-
import { Schemas } from 'aws-sdk'
10+
import {
11+
DescribeCodeBindingResponse,
12+
GetCodeBindingSourceResponse,
13+
PutCodeBindingResponse,
14+
} from '@aws-sdk/client-schemas'
1115
import * as sinon from 'sinon'
1216

1317
import {
@@ -61,8 +65,8 @@ describe('CodeDownloader', function () {
6165

6266
describe('codeDownloader', async function () {
6367
it('should return an error if the response body is not Buffer', async function () {
64-
const response: Schemas.GetCodeBindingSourceResponse = {
65-
Body: 'Invalied body',
68+
const response: GetCodeBindingSourceResponse = {
69+
Body: 'Invalied body' as any,
6670
}
6771
sandbox.stub(schemaClient, 'getCodeBindingSource').returns(Promise.resolve(response))
6872

@@ -75,8 +79,8 @@ describe('CodeDownloader', function () {
7579

7680
it('should return arrayBuffer for valid Body type', async function () {
7781
const myBuffer = Buffer.from('TEST STRING')
78-
const response: Schemas.GetCodeBindingSourceResponse = {
79-
Body: myBuffer,
82+
const response: GetCodeBindingSourceResponse = {
83+
Body: myBuffer as any,
8084
}
8185

8286
sandbox.stub(schemaClient, 'getCodeBindingSource').returns(Promise.resolve(response))
@@ -148,7 +152,7 @@ describe('CodeGenerator', function () {
148152

149153
describe('codeGenerator', async function () {
150154
it('should return the current status of code generation', async function () {
151-
const response: Schemas.PutCodeBindingResponse = {
155+
const response: PutCodeBindingResponse = {
152156
Status: CodeGenerationStatus.CREATE_IN_PROGRESS,
153157
}
154158
sandbox.stub(schemaClient, 'putCodeBinding').returns(Promise.resolve(response))
@@ -164,7 +168,7 @@ describe('CodeGenerator', function () {
164168
// If code bindings were not generated, but putCodeBinding was already called, ConflictException occurs
165169
// Return CREATE_IN_PROGRESS and keep polling in this case
166170
it('should return valid code generation status if it gets ConflictException', async function () {
167-
const response: Schemas.PutCodeBindingResponse = {
171+
const response: PutCodeBindingResponse = {
168172
Status: CodeGenerationStatus.CREATE_IN_PROGRESS,
169173
}
170174

@@ -224,10 +228,10 @@ describe('CodeGeneratorStatusPoller', function () {
224228

225229
describe('getCurrentStatus', async function () {
226230
it('should return the current status of code generation', async function () {
227-
const firstStatus: Schemas.DescribeCodeBindingResponse = {
231+
const firstStatus: DescribeCodeBindingResponse = {
228232
Status: CodeGenerationStatus.CREATE_IN_PROGRESS,
229233
}
230-
const secondStatus: Schemas.DescribeCodeBindingResponse = {
234+
const secondStatus: DescribeCodeBindingResponse = {
231235
Status: CodeGenerationStatus.CREATE_COMPLETE,
232236
}
233237

@@ -245,7 +249,7 @@ describe('CodeGeneratorStatusPoller', function () {
245249

246250
describe('codeGeneratorStatusPoller', async function () {
247251
it('fails if code generation status is invalid without retry', async function () {
248-
const schemaResponse: Schemas.DescribeCodeBindingResponse = {
252+
const schemaResponse: DescribeCodeBindingResponse = {
249253
Status: CodeGenerationStatus.CREATE_FAILED,
250254
}
251255

@@ -266,7 +270,7 @@ describe('CodeGeneratorStatusPoller', function () {
266270
})
267271

268272
it('times out after max attempts if status is still in progress', async function () {
269-
const schemaResponse: Schemas.DescribeCodeBindingResponse = {
273+
const schemaResponse: DescribeCodeBindingResponse = {
270274
Status: CodeGenerationStatus.CREATE_IN_PROGRESS,
271275
}
272276

@@ -290,7 +294,7 @@ describe('CodeGeneratorStatusPoller', function () {
290294
})
291295

292296
it('succeeds when code is previously generated without retry', async function () {
293-
const schemaResponse: Schemas.DescribeCodeBindingResponse = {
297+
const schemaResponse: DescribeCodeBindingResponse = {
294298
Status: CodeGenerationStatus.CREATE_COMPLETE,
295299
}
296300

@@ -402,7 +406,7 @@ describe('SchemaCodeDownload', function () {
402406
it('should generate code if download fails with ResourceNotFound and place it into requested directory', async function () {
403407
sandbox.stub(poller, 'pollForCompletion').returns(Promise.resolve('CREATE_COMPLETE'))
404408
const codeDownloaderStub = sandbox.stub(downloader, 'download')
405-
const codeGeneratorResponse: Schemas.PutCodeBindingResponse = {
409+
const codeGeneratorResponse: PutCodeBindingResponse = {
406410
Status: 'CREATE_IN_PROGRESS',
407411
}
408412
sandbox.stub(generator, 'generate').returns(Promise.resolve(codeGeneratorResponse))

0 commit comments

Comments
 (0)