Skip to content

Commit d34ddfe

Browse files
chungjacaws-toolkit-automationctlai95ashishrp-awslaileni-aws
authored
refactor(aws-toolkit-vscode): migrate aws-sdk v2 to v3 (aws#8183)
## Note **There is still a little bit more work needed for fully migrating aws-sdk v2 to v3, specifically all of these clients [here](https://github.com/aws/aws-toolkit-vscode/blob/59fd17fcfa22798e78d0df196290edb4a070f7ec/packages/core/scripts/build/generateServiceClient.ts#L232-L251) from the `generateServiceClient.ts` script** ## Problem AWS SDK V2 is at EOL ## Solution Migrate AWS SDK V2 to V3 This work has been done in the `feature/v2-to-v3-migration` feature branch and thus merging it into `master` Here are the PRs, which this does not include the merges from main and resolving conflicts: - aws#8043 - aws#8042 - aws#8046 - aws#8054 - aws#8041 - aws#8056 - aws#8081 - aws#8069 - aws#8067 - aws#8093 - aws#8095 - aws#8094 - aws#8171 - aws#8159 - aws#8175 - aws#8182 ## Testing Manually tested the [prerelease builds](https://github.com/aws/aws-toolkit-vscode/releases/tag/pre-v2-to-v3-migration) https://github.com/user-attachments/assets/b1d4795c-4027-462e-a195-509ac4a9d8ae --- - 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. --------- Co-authored-by: aws-toolkit-automation <[email protected]> Co-authored-by: Tai Lai <[email protected]> Co-authored-by: invictus <[email protected]> Co-authored-by: Laxman Reddy <[email protected]>
1 parent c76cded commit d34ddfe

File tree

151 files changed

+10708
-5534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+10708
-5534
lines changed

package-lock.json

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

packages/amazonq/test/unit/codewhisperer/service/codewhisperer.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
codeWhispererClient,
1313
} from 'aws-core-vscode/codewhisperer'
1414
import { globals, getClientId, getOperatingSystem } from 'aws-core-vscode/shared'
15-
import { AWSError, Request } from 'aws-sdk'
15+
import { Request } from 'aws-sdk'
16+
import { ServiceException } from '@smithy/smithy-client'
1617
import { createSpyClient } from 'aws-core-vscode/test'
1718

1819
describe('codewhisperer', async function () {
@@ -109,7 +110,7 @@ describe('codewhisperer', async function () {
109110
requestId: '',
110111
},
111112
}),
112-
} as Request<SendTelemetryEventResponse, AWSError>)
113+
} as Request<SendTelemetryEventResponse, ServiceException>)
113114

114115
const expectedUserContext = {
115116
ideCategory: 'VSCODE',
@@ -134,7 +135,7 @@ describe('codewhisperer', async function () {
134135
requestId: '',
135136
},
136137
}),
137-
} as Request<SendTelemetryEventResponse, AWSError>)
138+
} as Request<SendTelemetryEventResponse, ServiceException>)
138139

139140
const authUtilStub = sinon.stub(AuthUtil.instance, 'isValidEnterpriseSsoInUse').returns(isSso)
140141
await globals.telemetry.setTelemetryEnabled(isTelemetryEnabled)

packages/core/package.json

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,13 @@
547547
"@types/sinon": "^10.0.5",
548548
"@types/sinonjs__fake-timers": "^8.1.2",
549549
"@types/stream-buffers": "^3.0.7",
550+
"@types/svgdom": "^0.1.2",
550551
"@types/tcp-port-used": "^1.0.1",
551552
"@types/uuid": "^9.0.1",
552553
"@types/whatwg-url": "^11.0.4",
553554
"@types/xml2js": "^0.4.11",
554-
"@types/svgdom": "^0.1.2",
555555
"@vue/compiler-sfc": "^3.3.2",
556+
"aws-sdk-client-mock": "^4.1.0",
556557
"c8": "^9.0.0",
557558
"circular-dependency-plugin": "^5.2.2",
558559
"css-loader": "^6.10.0",
@@ -580,7 +581,7 @@
580581
"@amzn/amazon-q-developer-streaming-client": "file:../../src.gen/@amzn/amazon-q-developer-streaming-client",
581582
"@amzn/codewhisperer-streaming": "file:../../src.gen/@amzn/codewhisperer-streaming",
582583
"@amzn/sagemaker-client": "file:../../src.gen/@amzn/sagemaker-client/1.0.0.tgz",
583-
"@aws-sdk/credential-providers": "<3.731.0",
584+
"@aws-sdk/client-accessanalyzer": "^3.888.0",
584585
"@aws-sdk/client-api-gateway": "<3.731.0",
585586
"@aws-sdk/client-apprunner": "<3.731.0",
586587
"@aws-sdk/client-cloudcontrol": "<3.731.0",
@@ -592,19 +593,29 @@
592593
"@aws-sdk/client-docdb": "<3.731.0",
593594
"@aws-sdk/client-docdb-elastic": "<3.731.0",
594595
"@aws-sdk/client-ec2": "<3.731.0",
596+
"@aws-sdk/client-ecr": "~3.693.0",
597+
"@aws-sdk/client-ecs": "~3.693.0",
595598
"@aws-sdk/client-glue": "^3.852.0",
596599
"@aws-sdk/client-iam": "<3.731.0",
600+
"@aws-sdk/client-iot": "~3.693.0",
601+
"@aws-sdk/client-iotsecuretunneling": "~3.693.0",
597602
"@aws-sdk/client-lambda": "<3.731.0",
603+
"@aws-sdk/client-redshift": "~3.693.0",
604+
"@aws-sdk/client-redshift-data": "~3.693.0",
605+
"@aws-sdk/client-redshift-serverless": "~3.693.0",
598606
"@aws-sdk/client-s3": "<3.731.0",
599607
"@aws-sdk/client-s3-control": "^3.830.0",
600608
"@aws-sdk/client-sagemaker": "<3.696.0",
609+
"@aws-sdk/client-schemas": "~3.693.0",
610+
"@aws-sdk/client-secrets-manager": "~3.693.0",
611+
"@aws-sdk/client-sfn": "<3.731.0",
601612
"@aws-sdk/client-ssm": "<3.731.0",
602613
"@aws-sdk/client-sso": "<3.731.0",
603614
"@aws-sdk/client-sso-oidc": "<3.731.0",
604-
"@aws-sdk/client-sfn": "<3.731.0",
605615
"@aws-sdk/credential-provider-env": "<3.731.0",
606616
"@aws-sdk/credential-provider-process": "<3.731.0",
607617
"@aws-sdk/credential-provider-sso": "<3.731.0",
618+
"@aws-sdk/credential-providers": "<3.731.0",
608619
"@aws-sdk/lib-storage": "<3.731.0",
609620
"@aws-sdk/property-provider": "<3.731.0",
610621
"@aws-sdk/protocol-http": "<3.731.0",
@@ -621,6 +632,7 @@
621632
"@smithy/service-error-classification": "^4.0.1",
622633
"@smithy/shared-ini-file-loader": "^4.0.0",
623634
"@smithy/util-retry": "^4.0.1",
635+
"@svgdotjs/svg.js": "^3.0.16",
624636
"@vscode/debugprotocol": "^1.57.0",
625637
"@zip.js/zip.js": "^2.7.41",
626638
"adm-zip": "^0.5.10",
@@ -639,6 +651,7 @@
639651
"http2": "^3.3.6",
640652
"i18n-ts": "^1.0.5",
641653
"immutable": "^4.3.0",
654+
"jaro-winkler": "^0.2.8",
642655
"jose": "5.4.1",
643656
"js-yaml": "^4.1.0",
644657
"jsonc-parser": "^3.2.0",
@@ -648,9 +661,11 @@
648661
"mime-types": "^2.1.32",
649662
"node-fetch": "^2.7.0",
650663
"portfinder": "^1.0.32",
664+
"protobufjs": "^7.2.6",
651665
"semver": "^7.5.4",
652666
"stream-buffers": "^3.0.2",
653667
"strip-ansi": "^5.2.0",
668+
"svgdom": "^0.1.0",
654669
"tcp-port-used": "^1.0.1",
655670
"vscode-languageclient": "^6.1.4",
656671
"vscode-languageserver": "^6.1.1",
@@ -663,11 +678,7 @@
663678
"winston-transport": "^4.6.0",
664679
"ws": "^8.16.0",
665680
"xml2js": "^0.6.1",
666-
"yaml-cfn": "^0.3.2",
667-
"protobufjs": "^7.2.6",
668-
"@svgdotjs/svg.js": "^3.0.16",
669-
"svgdom": "^0.1.0",
670-
"jaro-winkler": "^0.2.8"
681+
"yaml-cfn": "^0.3.2"
671682
},
672683
"overrides": {
673684
"webfont": {

packages/core/src/awsService/accessanalyzer/vue/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ export type PolicyChecksCheckType = 'CheckNoNewAccess' | 'CheckAccessNotGranted'
3030

3131
export type PolicyChecksPolicyType = 'Identity' | 'Resource'
3232

33-
export type ValidatePolicyFindingType = 'ERROR' | 'SECURITY_WARNING' | 'SUGGESTION' | 'WARNING'
34-
3533
export type PolicyChecksResult = 'Success' | 'Warning' | 'Error'
3634

3735
export type PolicyChecksUiClick =

packages/core/src/awsService/accessanalyzer/vue/iamPolicyChecks.ts

Lines changed: 85 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { localize } from '../../../shared/utilities/vsCodeUtils'
1111
import { VueWebview, VueWebviewPanel } from '../../../webviews/main'
1212
import { ExtContext } from '../../../shared/extensions'
1313
import { telemetry } from '../../../shared/telemetry/telemetry'
14-
import { AccessAnalyzer, SharedIniFileCredentials } from 'aws-sdk'
14+
import { AccessAnalyzerClient, ValidatePolicyCommand } from '@aws-sdk/client-accessanalyzer'
15+
import { fromIni } from '@aws-sdk/credential-providers'
1516
import { ToolkitError } from '../../../shared/errors'
1617
import { makeTemporaryToolkitFolder, tryRemoveFolder } from '../../../shared/filesystemUtilities'
1718
import globals from '../../../shared/extensionGlobals'
@@ -23,7 +24,6 @@ import {
2324
PolicyChecksPolicyType,
2425
PolicyChecksResult,
2526
PolicyChecksUiClick,
26-
ValidatePolicyFindingType,
2727
} from './constants'
2828
import { S3Client, parseS3Uri } from '../../../shared/clients/s3'
2929
import { ExpiredTokenException } from '@aws-sdk/client-sso-oidc'
@@ -61,7 +61,7 @@ export class IamPolicyChecksWebview extends VueWebview {
6161

6262
public constructor(
6363
private readonly data: IamPolicyChecksInitialData,
64-
private client: AccessAnalyzer,
64+
private client: AccessAnalyzerClient,
6565
private readonly region: string,
6666
public readonly onChangeInputPath = new vscode.EventEmitter<string>(),
6767
public readonly onChangeCheckNoNewAccessFilePath = new vscode.EventEmitter<string>(),
@@ -179,85 +179,94 @@ export class IamPolicyChecksWebview extends VueWebview {
179179
documentType,
180180
inputPolicyType: policyType ? policyType : 'None',
181181
})
182-
this.client.config.credentials = new SharedIniFileCredentials({
182+
this.client.config.credentials = fromIni({
183183
profile: `${getProfileName()}`,
184184
}) // We need to detect changes in the user's credentials
185-
this.client.validatePolicy(
186-
{
187-
policyDocument: IamPolicyChecksWebview.editedDocument,
188-
policyType: policyType === 'Identity' ? 'IDENTITY_POLICY' : 'RESOURCE_POLICY',
189-
},
190-
(err, data) => {
191-
if (err) {
185+
this.client
186+
.send(
187+
new ValidatePolicyCommand({
188+
policyDocument: IamPolicyChecksWebview.editedDocument,
189+
policyType: policyType === 'Identity' ? 'IDENTITY_POLICY' : 'RESOURCE_POLICY',
190+
})
191+
)
192+
.then((data) => {
193+
if (data.findings && data.findings.length > 0) {
192194
span.record({
193-
findingsCount: 0,
195+
findingsCount: data.findings.length,
194196
})
195-
if (err instanceof ExpiredTokenException) {
196-
this.onValidatePolicyResponse.fire([
197-
IamPolicyChecksConstants.InvalidAwsCredentials,
198-
getResultCssColor('Error'),
199-
])
200-
} else {
201-
this.onValidatePolicyResponse.fire([err.message, getResultCssColor('Error')])
202-
}
203-
} else {
204-
if (data.findings.length > 0) {
205-
span.record({
206-
findingsCount: data.findings.length,
207-
})
208-
// eslint-disable-next-line unicorn/no-array-for-each
209-
data.findings.forEach((finding: AccessAnalyzer.ValidatePolicyFinding) => {
210-
const message = `${finding.findingType}: ${finding.issueCode} - ${finding.findingDetails} Learn more: ${finding.learnMoreLink}`
211-
if ((finding.findingType as ValidatePolicyFindingType) === 'ERROR') {
212-
diagnostics.push(
213-
new vscode.Diagnostic(
214-
new vscode.Range(
215-
finding.locations[0].span.start.line,
216-
finding.locations[0].span.start.offset,
217-
finding.locations[0].span.end.line,
218-
finding.locations[0].span.end.offset
219-
),
220-
message,
221-
vscode.DiagnosticSeverity.Error
222-
)
223-
)
224-
validatePolicyDiagnosticCollection.set(
225-
IamPolicyChecksWebview.editedDocumentUri,
226-
diagnostics
197+
// eslint-disable-next-line unicorn/no-array-for-each
198+
data.findings.forEach((finding) => {
199+
const locationSpan = finding.locations?.[0].span
200+
if (
201+
!locationSpan?.start?.line ||
202+
!locationSpan.start.offset ||
203+
!locationSpan.end?.line ||
204+
!locationSpan.end.offset
205+
) {
206+
return
207+
}
208+
const message = `${finding.findingType}: ${finding.issueCode} - ${finding.findingDetails} Learn more: ${finding.learnMoreLink}`
209+
if (finding.findingType === 'ERROR') {
210+
diagnostics.push(
211+
new vscode.Diagnostic(
212+
new vscode.Range(
213+
locationSpan.start.line,
214+
locationSpan.start.offset,
215+
locationSpan.end.line,
216+
locationSpan.end.offset
217+
),
218+
message,
219+
vscode.DiagnosticSeverity.Error
227220
)
228-
} else {
229-
diagnostics.push(
230-
new vscode.Diagnostic(
231-
new vscode.Range(
232-
finding.locations[0].span.start.line,
233-
finding.locations[0].span.start.offset,
234-
finding.locations[0].span.end.line,
235-
finding.locations[0].span.end.offset
236-
),
237-
message,
238-
vscode.DiagnosticSeverity.Warning
239-
)
221+
)
222+
validatePolicyDiagnosticCollection.set(
223+
IamPolicyChecksWebview.editedDocumentUri,
224+
diagnostics
225+
)
226+
} else {
227+
diagnostics.push(
228+
new vscode.Diagnostic(
229+
new vscode.Range(
230+
locationSpan.start.line,
231+
locationSpan.start.offset,
232+
locationSpan.end.line,
233+
locationSpan.end.offset
234+
),
235+
message,
236+
vscode.DiagnosticSeverity.Warning
240237
)
241-
validatePolicyDiagnosticCollection.set(
242-
IamPolicyChecksWebview.editedDocumentUri,
243-
diagnostics
244-
)
245-
}
246-
})
247-
this.onValidatePolicyResponse.fire([
248-
IamPolicyChecksConstants.ValidatePolicySuccessWithFindings,
249-
getResultCssColor('Warning'),
250-
])
251-
void vscode.commands.executeCommand('workbench.actions.view.problems')
252-
} else {
253-
this.onValidatePolicyResponse.fire([
254-
IamPolicyChecksConstants.ValidatePolicySuccessNoFindings,
255-
getResultCssColor('Success'),
256-
])
257-
}
238+
)
239+
validatePolicyDiagnosticCollection.set(
240+
IamPolicyChecksWebview.editedDocumentUri,
241+
diagnostics
242+
)
243+
}
244+
})
245+
this.onValidatePolicyResponse.fire([
246+
IamPolicyChecksConstants.ValidatePolicySuccessWithFindings,
247+
getResultCssColor('Warning'),
248+
])
249+
void vscode.commands.executeCommand('workbench.actions.view.problems')
250+
} else {
251+
this.onValidatePolicyResponse.fire([
252+
IamPolicyChecksConstants.ValidatePolicySuccessNoFindings,
253+
getResultCssColor('Success'),
254+
])
255+
}
256+
})
257+
.catch((err) => {
258+
span.record({
259+
findingsCount: 0,
260+
})
261+
if (err instanceof ExpiredTokenException) {
262+
this.onValidatePolicyResponse.fire([
263+
IamPolicyChecksConstants.InvalidAwsCredentials,
264+
getResultCssColor('Error'),
265+
])
266+
} else {
267+
this.onValidatePolicyResponse.fire([err.message, getResultCssColor('Error')])
258268
}
259-
}
260-
)
269+
})
261270
})
262271
return
263272
} else {
@@ -781,7 +790,7 @@ const Panel = VueWebview.compilePanel(IamPolicyChecksWebview)
781790
export async function renderIamPolicyChecks(context: ExtContext): Promise<VueWebviewPanel | undefined> {
782791
const logger: Logger = getLogger()
783792
try {
784-
const client = new AccessAnalyzer({ region: context.regionProvider.defaultRegionId })
793+
const client = new AccessAnalyzerClient({ region: context.regionProvider.defaultRegionId })
785794
// Read from settings to auto-fill some inputs
786795
const checkNoNewAccessFilePath: string = vscode.workspace
787796
.getConfiguration()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as picker from '../../../shared/ui/picker'
1111
import * as vscode from 'vscode'
1212
import { ProgressLocation } from 'vscode'
1313

14-
import { Stage } from 'aws-sdk/clients/apigateway'
14+
import { Stage } from '@aws-sdk/client-api-gateway'
1515
import { ApiGatewayClient } from '../../../shared/clients/apiGateway'
1616
import { defaultDnsSuffix, RegionProvider } from '../../../shared/regions/regionProvider'
1717
import { getLogger } from '../../../shared/logger/logger'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { AWSTreeNodeBase } from '../../../shared/treeview/nodes/awsTreeNodeBase'
1212
import { PlaceholderNode } from '../../../shared/treeview/nodes/placeholderNode'
1313
import { compareTreeItems, makeChildrenNodes } from '../../../shared/treeview/utils'
1414
import { ApiGatewayClient } from '../../../shared/clients/apiGateway'
15-
import { RestApi } from 'aws-sdk/clients/apigateway'
15+
import { RestApi } from '@aws-sdk/client-api-gateway'
1616
import { toArrayAsync, toMap, updateInPlace } from '../../../shared/utilities/collectionUtils'
1717
import { RestApiNode } from './apiNodes'
1818

0 commit comments

Comments
 (0)