Skip to content

Commit 64adf3e

Browse files
authored
refactor(iot): migrate to aws-sdk v3 part 2 (aws#8081)
## Problem AWS SDK V2 is EOL. ## Solution Migrate IoT imports 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 17221e1 commit 64adf3e

13 files changed

+36
-36
lines changed

packages/core/src/awsService/iot/commands/attachPolicy.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { PromptResult } from '../../../shared/ui/prompter'
1212
import { IotClient } from '../../../shared/clients/iotClient'
1313
import { isValidResponse } from '../../../shared/wizards/wizard'
1414
import { IotCertWithPoliciesNode, IotThingCertNode } from '../explorer/iotCertificateNode'
15-
import { Iot } from 'aws-sdk'
15+
import { ListPoliciesResponse, Policy } from '@aws-sdk/client-iot'
1616
import { IotNode } from '../explorer/iotNodes'
1717

1818
export type PolicyGen = typeof getPolicyList
@@ -69,8 +69,8 @@ function getBaseNode(node: IotThingCertNode | IotCertWithPoliciesNode): IotNode
6969
/**
7070
* Prompts the user to pick a policy to attach.
7171
*/
72-
async function promptForPolicy(iot: IotClient, policyFetch: PolicyGen): Promise<PromptResult<Iot.Policy>> {
73-
const placeHolder: DataQuickPickItem<Iot.Policy> = {
72+
async function promptForPolicy(iot: IotClient, policyFetch: PolicyGen): Promise<PromptResult<Policy>> {
73+
const placeHolder: DataQuickPickItem<Policy> = {
7474
label: 'No policies found',
7575
data: undefined,
7676
}
@@ -87,10 +87,10 @@ async function promptForPolicy(iot: IotClient, policyFetch: PolicyGen): Promise<
8787
*/
8888
async function* getPolicyList(iot: IotClient) {
8989
let marker: string | undefined = undefined
90-
let filteredPolicies: Iot.Policy[]
90+
let filteredPolicies: Policy[]
9191
do {
9292
try {
93-
const policyResponse: Iot.ListPoliciesResponse = await iot.listPolicies({ marker })
93+
const policyResponse: ListPoliciesResponse = await iot.listPolicies({ marker })
9494
marker = policyResponse.nextMarker
9595

9696
/* The policy name and arn should always be defined when using the

packages/core/src/awsService/iot/commands/createCert.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { localize } from '../../../shared/utilities/vsCodeUtils'
1010
import { showViewLogsMessage } from '../../../shared/utilities/messages'
1111
import { IotCertsFolderNode } from '../explorer/iotCertFolderNode'
1212
import { fileExists } from '../../../shared/filesystemUtilities'
13-
import { Iot } from 'aws-sdk'
13+
import { CreateKeysAndCertificateResponse } from '@aws-sdk/client-iot'
1414
import { fs } from '../../../shared/fs/fs'
1515

1616
// eslint-disable-next-line @typescript-eslint/naming-convention
@@ -34,7 +34,7 @@ export async function createCertificateCommand(
3434
return
3535
}
3636

37-
let certificate: Iot.CreateKeysAndCertificateResponse
37+
let certificate: CreateKeysAndCertificateResponse
3838

3939
try {
4040
certificate = await node.iot.createCertificateAndKeys({

packages/core/src/awsService/iot/explorer/iotPolicyNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import * as vscode from 'vscode'
7-
import { Iot } from 'aws-sdk'
87
import { IotClient, IotPolicy } from '../../../shared/clients/iotClient'
98

109
import { AWSResourceNode } from '../../../shared/treeview/nodes/awsResourceNode'
@@ -20,6 +19,7 @@ import { localize } from '../../../shared/utilities/vsCodeUtils'
2019
import { getIcon } from '../../../shared/icons'
2120
import { Settings } from '../../../shared/settings'
2221
import { ClassToInterfaceType } from '../../../shared/utilities/tsUtils'
22+
import { PolicyVersion } from '@aws-sdk/client-iot'
2323

2424
/**
2525
* Represents an IoT Policy that may have either a Certificate Node or the
@@ -101,7 +101,7 @@ export class IotPolicyWithVersionsNode extends IotPolicyNode {
101101
}
102102

103103
public async updateChildren(): Promise<void> {
104-
const versions: Map<string, Iot.PolicyVersion> = toMap(
104+
const versions: Map<string, PolicyVersion> = toMap(
105105
await toArrayAsync(this.iot.listPolicyVersions({ policyName: this.policy.name })),
106106
(version) => version.versionId
107107
)

packages/core/src/awsService/iot/explorer/iotPolicyVersionNode.ts

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

6-
import { Iot } from 'aws-sdk'
6+
import { PolicyVersion } from '@aws-sdk/client-iot'
77
import { IotClient, IotPolicy } from '../../../shared/clients/iotClient'
88
import { AWSResourceNode } from '../../../shared/treeview/nodes/awsResourceNode'
99
import { AWSTreeNodeBase } from '../../../shared/treeview/nodes/awsTreeNodeBase'
@@ -19,7 +19,7 @@ import { formatLocalized } from '../../../shared/datetime'
1919
export class IotPolicyVersionNode extends AWSTreeNodeBase implements AWSResourceNode {
2020
public constructor(
2121
public policy: IotPolicy,
22-
public version: Iot.PolicyVersion,
22+
public version: PolicyVersion,
2323
public isDefault: boolean,
2424
public readonly parent: IotPolicyWithVersionsNode,
2525
public readonly iot: IotClient
@@ -35,7 +35,7 @@ export class IotPolicyVersionNode extends AWSTreeNodeBase implements AWSResource
3535
this.update(version)
3636
}
3737

38-
public update(version: Iot.PolicyVersion): void {
38+
public update(version: PolicyVersion): void {
3939
this.version = version
4040
this.isDefault = version.isDefaultVersion ?? false
4141
this.tooltip = localize(

packages/core/src/test/awsService/iot/commands/createCert.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { createCertificateCommand } from '../../../../awsService/iot/commands/cr
99
import { IotNode } from '../../../../awsService/iot/explorer/iotNodes'
1010
import { IotClient } from '../../../../shared/clients/iotClient'
1111
import { IotCertsFolderNode } from '../../../../awsService/iot/explorer/iotCertFolderNode'
12-
import { Iot } from 'aws-sdk'
12+
import { CreateKeysAndCertificateResponse } from '@aws-sdk/client-iot'
1313
import { getTestWindow } from '../../../shared/vscode/window'
1414
import assert from 'assert'
1515

@@ -21,7 +21,7 @@ describe('createCertificateCommand', function () {
2121
const certificateArn = 'arn'
2222
const certificatePem = 'certPem'
2323
const keyPair = { PrivateKey: 'private', PublicKey: 'public' }
24-
const certificate: Iot.CreateKeysAndCertificateResponse = { certificateId, certificateArn, certificatePem, keyPair }
24+
const certificate: CreateKeysAndCertificateResponse = { certificateId, certificateArn, certificatePem, keyPair }
2525
let iot: IotClient
2626
let node: IotCertsFolderNode
2727
let saveLocation: vscode.Uri | undefined = vscode.Uri.file('/certificate.txt')

packages/core/src/test/awsService/iot/commands/deletePolicy.test.ts

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

66
import * as sinon from 'sinon'
77
import * as vscode from 'vscode'
8-
import { Iot } from 'aws-sdk'
8+
import { PolicyVersion } from '@aws-sdk/client-iot'
99
import { deletePolicyCommand } from '../../../../awsService/iot/commands/deletePolicy'
1010
import { IotPolicyFolderNode } from '../../../../awsService/iot/explorer/iotPolicyFolderNode'
1111
import { IotPolicyWithVersionsNode } from '../../../../awsService/iot/explorer/iotPolicyNode'
@@ -42,8 +42,8 @@ describe('deletePolicyCommand', function () {
4242
iot.listPolicyTargets = listPolicyStub
4343
const policyVersions = ['1']
4444
const listPolicyVersionsStub = sinon.stub().returns(
45-
asyncGenerator<Iot.PolicyVersion>(
46-
policyVersions.map<Iot.PolicyVersion>((versionId) => {
45+
asyncGenerator<PolicyVersion>(
46+
policyVersions.map<PolicyVersion>((versionId) => {
4747
return {
4848
versionId: versionId,
4949
}
@@ -86,8 +86,8 @@ describe('deletePolicyCommand', function () {
8686
iot.listPolicyTargets = listPolicyStub
8787
const policyVersions = ['1', '2']
8888
const listPolicyVersionsStub = sinon.stub().returns(
89-
asyncGenerator<Iot.PolicyVersion>(
90-
policyVersions.map<Iot.PolicyVersion>((versionId) => {
89+
asyncGenerator<PolicyVersion>(
90+
policyVersions.map<PolicyVersion>((versionId) => {
9191
return {
9292
versionId: versionId,
9393
}

packages/core/src/test/awsService/iot/explorer/iotCertFolderNode.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import assert from 'assert'
77
import { MoreResultsNode } from '../../../../awsexplorer/moreResultsNode'
88
import { IotNode } from '../../../../awsService/iot/explorer/iotNodes'
99
import { IotCertificate, IotClient } from '../../../../shared/clients/iotClient'
10-
import { Iot } from 'aws-sdk'
10+
import { Certificate } from '@aws-sdk/client-iot'
1111
import { AWSTreeNodeBase } from '../../../../shared/treeview/nodes/awsTreeNodeBase'
1212
import { IotCertWithPoliciesNode } from '../../../../awsService/iot/explorer/iotCertificateNode'
1313
import { IotCertsFolderNode } from '../../../../awsService/iot/explorer/iotCertFolderNode'
@@ -21,7 +21,7 @@ describe('IotCertFolderNode', function () {
2121
let iot: IotClient
2222
let config: TestSettings
2323

24-
const cert: Iot.Certificate = {
24+
const cert: Certificate = {
2525
certificateId: 'cert',
2626
certificateArn: 'arn',
2727
status: 'ACTIVE',

packages/core/src/test/awsService/iot/explorer/iotCertificateNode.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import assert from 'assert'
77
import { MoreResultsNode } from '../../../../awsexplorer/moreResultsNode'
88
import { IotClient, IotPolicy } from '../../../../shared/clients/iotClient'
9-
import { Iot } from 'aws-sdk'
9+
import { Policy } from '@aws-sdk/client-iot'
1010
import { AWSTreeNodeBase } from '../../../../shared/treeview/nodes/awsTreeNodeBase'
1111
import { IotPolicyCertNode } from '../../../../awsService/iot/explorer/iotPolicyNode'
1212
import { IotCertWithPoliciesNode } from '../../../../awsService/iot/explorer/iotCertificateNode'
@@ -22,7 +22,7 @@ describe('IotCertificateNode', function () {
2222
let config: TestSettings
2323
const certArn = 'certArn'
2424
const cert = { id: 'cert', arn: certArn, activeStatus: 'ACTIVE', creationDate: new Date(0) }
25-
const policy: Iot.Policy = { policyName: 'policy', policyArn: 'arn' }
25+
const policy: Policy = { policyName: 'policy', policyArn: 'arn' }
2626
const expectedPolicy: IotPolicy = { name: 'policy', arn: 'arn' }
2727

2828
function assertPolicyNode(node: AWSTreeNodeBase, expectedPolicy: IotPolicy): void {

packages/core/src/test/awsService/iot/explorer/iotPolicyFolderNode.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import assert from 'assert'
77
import { MoreResultsNode } from '../../../../awsexplorer/moreResultsNode'
88
import { IotNode } from '../../../../awsService/iot/explorer/iotNodes'
99
import { IotClient, IotPolicy } from '../../../../shared/clients/iotClient'
10-
import { Iot } from 'aws-sdk'
10+
import { Policy } from '@aws-sdk/client-iot'
1111
import { AWSTreeNodeBase } from '../../../../shared/treeview/nodes/awsTreeNodeBase'
1212
import { IotPolicyWithVersionsNode } from '../../../../awsService/iot/explorer/iotPolicyNode'
1313
import { IotPolicyFolderNode } from '../../../../awsService/iot/explorer/iotPolicyFolderNode'
@@ -20,7 +20,7 @@ describe('IotPolicyFolderNode', function () {
2020

2121
let iot: IotClient
2222
let config: TestSettings
23-
const policy: Iot.Policy = { policyName: 'policy', policyArn: 'arn' }
23+
const policy: Policy = { policyName: 'policy', policyArn: 'arn' }
2424
const expectedPolicy: IotPolicy = { name: 'policy', arn: 'arn' }
2525

2626
function assertPolicyNode(node: AWSTreeNodeBase, expectedPolicy: IotPolicy): void {

packages/core/src/test/awsService/iot/explorer/iotPolicyNode.test.ts

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

66
import assert from 'assert'
77
import { IotClient, IotPolicy } from '../../../../shared/clients/iotClient'
8-
import { Iot } from 'aws-sdk'
8+
import { PolicyVersion } from '@aws-sdk/client-iot'
99
import { AWSTreeNodeBase } from '../../../../shared/treeview/nodes/awsTreeNodeBase'
1010
import { asyncGenerator } from '../../../../shared/utilities/collectionUtils'
1111
import { IotPolicyWithVersionsNode } from '../../../../awsService/iot/explorer/iotPolicyNode'
@@ -19,12 +19,12 @@ describe('IotPolicyNode', function () {
1919
let config: TestSettings
2020
const policyName = 'policy'
2121
const expectedPolicy: IotPolicy = { name: policyName, arn: 'arn' }
22-
const policyVersion: Iot.PolicyVersion = { versionId: 'V1', isDefaultVersion: true }
22+
const policyVersion: PolicyVersion = { versionId: 'V1', isDefaultVersion: true }
2323

2424
function assertPolicyVersionNode(
2525
node: AWSTreeNodeBase,
2626
expectedPolicy: IotPolicy,
27-
expectedVersion: Iot.PolicyVersion
27+
expectedVersion: PolicyVersion
2828
): void {
2929
assert.ok(node instanceof IotPolicyVersionNode, `Node ${node} should be a Policy Version Node`)
3030
assert.deepStrictEqual((node as IotPolicyVersionNode).version, expectedVersion)
@@ -39,7 +39,7 @@ describe('IotPolicyNode', function () {
3939
describe('getChildren', function () {
4040
it('gets children', async function () {
4141
const versions = [{ versionId: 'V1', isDefaultVersion: true }]
42-
const stub = sinon.stub().returns(asyncGenerator<Iot.PolicyVersion>(versions))
42+
const stub = sinon.stub().returns(asyncGenerator<PolicyVersion>(versions))
4343
iot.listPolicyVersions = stub
4444
const node = new IotPolicyWithVersionsNode(
4545
expectedPolicy,

0 commit comments

Comments
 (0)