diff --git a/package-lock.json b/package-lock.json index fa324e732b2..2cef66ef15f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20640,7 +20640,9 @@ } }, "node_modules/@sinonjs/text-encoding": { - "version": "0.7.1", + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.3.tgz", + "integrity": "sha512-DE427ROAphMQzU4ENbliGYrBSYPXF+TtLg9S8vzeA+OF4ZKzoDdzfL8sxuMUGS/lgRhM6j1URSk9ghf7Xo1tyA==", "dev": true, "license": "(Unlicense OR Apache-2.0)" }, @@ -23484,6 +23486,130 @@ "node": ">= 10.0.0" } }, + "node_modules/aws-sdk-client-mock": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/aws-sdk-client-mock/-/aws-sdk-client-mock-4.1.0.tgz", + "integrity": "sha512-h/tOYTkXEsAcV3//6C1/7U4ifSpKyJvb6auveAepqqNJl6TdZaPFEtKjBQNf8UxQdDP850knB2i/whq4zlsxJw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/sinon": "^17.0.3", + "sinon": "^18.0.1", + "tslib": "^2.1.0" + } + }, + "node_modules/aws-sdk-client-mock/node_modules/@sinonjs/commons": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz", + "integrity": "sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/aws-sdk-client-mock/node_modules/@sinonjs/fake-timers": { + "version": "11.2.2", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-11.2.2.tgz", + "integrity": "sha512-G2piCSxQ7oWOxwGSAyFHfPIsyeJGXYtc6mFbnFA+kRXkiEnTl8c/8jul2S329iFBnDI9HGoeWWAZvuvOkZccgw==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@sinonjs/commons": "^3.0.0" + } + }, + "node_modules/aws-sdk-client-mock/node_modules/@sinonjs/samsam": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-8.0.3.tgz", + "integrity": "sha512-hw6HbX+GyVZzmaYNh82Ecj1vdGZrqVIn/keDTg63IgAwiQPO+xCz99uG6Woqgb4tM0mUiFENKZ4cqd7IX94AXQ==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@sinonjs/commons": "^3.0.1", + "type-detect": "^4.1.0" + } + }, + "node_modules/aws-sdk-client-mock/node_modules/@sinonjs/samsam/node_modules/type-detect": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.1.0.tgz", + "integrity": "sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/aws-sdk-client-mock/node_modules/@types/sinon": { + "version": "17.0.4", + "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-17.0.4.tgz", + "integrity": "sha512-RHnIrhfPO3+tJT0s7cFaXGZvsL4bbR3/k7z3P312qMS4JaS2Tk+KiwiLx1S0rQ56ERj00u1/BtdyVd0FY+Pdew==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/sinonjs__fake-timers": "*" + } + }, + "node_modules/aws-sdk-client-mock/node_modules/just-extend": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-6.2.0.tgz", + "integrity": "sha512-cYofQu2Xpom82S6qD778jBDpwvvy39s1l/hrYij2u9AMdQcGRpaBu6kY4mVhuno5kJVi1DAz4aiphA2WI1/OAw==", + "dev": true, + "license": "MIT" + }, + "node_modules/aws-sdk-client-mock/node_modules/nise": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/nise/-/nise-6.1.1.tgz", + "integrity": "sha512-aMSAzLVY7LyeM60gvBS423nBmIPP+Wy7St7hsb+8/fc1HmeoHJfLO8CKse4u3BtOZvQLJghYPI2i/1WZrEj5/g==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@sinonjs/commons": "^3.0.1", + "@sinonjs/fake-timers": "^13.0.1", + "@sinonjs/text-encoding": "^0.7.3", + "just-extend": "^6.2.0", + "path-to-regexp": "^8.1.0" + } + }, + "node_modules/aws-sdk-client-mock/node_modules/nise/node_modules/@sinonjs/fake-timers": { + "version": "13.0.5", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-13.0.5.tgz", + "integrity": "sha512-36/hTbH2uaWuGVERyC6da9YwGWnzUZXuPro/F2LfsdOsLnCojz/iSH8MxUt/FD2S5XBSVPhmArFUXcpCQ2Hkiw==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@sinonjs/commons": "^3.0.1" + } + }, + "node_modules/aws-sdk-client-mock/node_modules/path-to-regexp": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.3.0.tgz", + "integrity": "sha512-7jdwVIRtsP8MYpdXSwOS0YdD0Du+qOoF/AEPIt88PcCFrZCzx41oxku1jD88hZBwbNUIEfpqvuhjFaMAqMTWnA==", + "dev": true, + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/aws-sdk-client-mock/node_modules/sinon": { + "version": "18.0.1", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-18.0.1.tgz", + "integrity": "sha512-a2N2TDY1uGviajJ6r4D1CyRAkzE9NNVlYOV1wX5xQDuAk0ONgzgRl0EjCQuRCPxOwp13ghsMwt9Gdldujs39qw==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@sinonjs/commons": "^3.0.1", + "@sinonjs/fake-timers": "11.2.2", + "@sinonjs/samsam": "^8.0.0", + "diff": "^5.2.0", + "nise": "^6.0.0", + "supports-color": "^7" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/sinon" + } + }, "node_modules/aws-sdk/node_modules/uuid": { "version": "8.0.0", "license": "MIT", @@ -25191,7 +25317,9 @@ "license": "MIT" }, "node_modules/diff": { - "version": "5.1.0", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.2.0.tgz", + "integrity": "sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==", "license": "BSD-3-Clause", "engines": { "node": ">=0.3.1" @@ -34393,6 +34521,8 @@ "@aws-sdk/client-ec2": "<3.731.0", "@aws-sdk/client-glue": "^3.852.0", "@aws-sdk/client-iam": "<3.731.0", + "@aws-sdk/client-iot": "~3.693.0", + "@aws-sdk/client-iotsecuretunneling": "~3.693.0", "@aws-sdk/client-lambda": "<3.731.0", "@aws-sdk/client-s3": "<3.731.0", "@aws-sdk/client-s3-control": "^3.830.0", @@ -34506,6 +34636,7 @@ "@types/whatwg-url": "^11.0.4", "@types/xml2js": "^0.4.11", "@vue/compiler-sfc": "^3.3.2", + "aws-sdk-client-mock": "^4.1.0", "c8": "^9.0.0", "circular-dependency-plugin": "^5.2.2", "css-loader": "^6.10.0", @@ -34790,6 +34921,288 @@ "node": ">=16.0.0" } }, + "packages/core/node_modules/@aws-sdk/client-iot": { + "version": "3.693.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/client-iot/-/client-iot-3.693.0.tgz", + "integrity": "sha512-0EOKH6CjDHMdE1NSDdtZ8/zov+Xf1MovWvAeQGs76ec4mL2VWP5HvePjjdkGoOo0KC9k/AqOVVc0UOZjK0iCQw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/sha256-browser": "5.2.0", + "@aws-crypto/sha256-js": "5.2.0", + "@aws-sdk/client-sso-oidc": "3.693.0", + "@aws-sdk/client-sts": "3.693.0", + "@aws-sdk/core": "3.693.0", + "@aws-sdk/credential-provider-node": "3.693.0", + "@aws-sdk/middleware-host-header": "3.693.0", + "@aws-sdk/middleware-logger": "3.693.0", + "@aws-sdk/middleware-recursion-detection": "3.693.0", + "@aws-sdk/middleware-user-agent": "3.693.0", + "@aws-sdk/region-config-resolver": "3.693.0", + "@aws-sdk/types": "3.692.0", + "@aws-sdk/util-endpoints": "3.693.0", + "@aws-sdk/util-user-agent-browser": "3.693.0", + "@aws-sdk/util-user-agent-node": "3.693.0", + "@smithy/config-resolver": "^3.0.11", + "@smithy/core": "^2.5.2", + "@smithy/fetch-http-handler": "^4.1.0", + "@smithy/hash-node": "^3.0.9", + "@smithy/invalid-dependency": "^3.0.9", + "@smithy/middleware-content-length": "^3.0.11", + "@smithy/middleware-endpoint": "^3.2.2", + "@smithy/middleware-retry": "^3.0.26", + "@smithy/middleware-serde": "^3.0.9", + "@smithy/middleware-stack": "^3.0.9", + "@smithy/node-config-provider": "^3.1.10", + "@smithy/node-http-handler": "^3.3.0", + "@smithy/protocol-http": "^4.1.6", + "@smithy/smithy-client": "^3.4.3", + "@smithy/types": "^3.7.0", + "@smithy/url-parser": "^3.0.9", + "@smithy/util-base64": "^3.0.0", + "@smithy/util-body-length-browser": "^3.0.0", + "@smithy/util-body-length-node": "^3.0.0", + "@smithy/util-defaults-mode-browser": "^3.0.26", + "@smithy/util-defaults-mode-node": "^3.0.26", + "@smithy/util-endpoints": "^2.1.5", + "@smithy/util-middleware": "^3.0.9", + "@smithy/util-retry": "^3.0.9", + "@smithy/util-utf8": "^3.0.0", + "@types/uuid": "^9.0.1", + "tslib": "^2.6.2", + "uuid": "^9.0.1" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "packages/core/node_modules/@aws-sdk/client-iot/node_modules/@smithy/fetch-http-handler": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/@smithy/fetch-http-handler/-/fetch-http-handler-4.1.3.tgz", + "integrity": "sha512-6SxNltSncI8s689nvnzZQc/dPXcpHQ34KUj6gR/HBroytKOd/isMG3gJF/zBE1TBmTT18TXyzhg3O3SOOqGEhA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/protocol-http": "^4.1.8", + "@smithy/querystring-builder": "^3.0.11", + "@smithy/types": "^3.7.2", + "@smithy/util-base64": "^3.0.0", + "tslib": "^2.6.2" + } + }, + "packages/core/node_modules/@aws-sdk/client-iot/node_modules/@smithy/middleware-retry": { + "version": "3.0.34", + "resolved": "https://registry.npmjs.org/@smithy/middleware-retry/-/middleware-retry-3.0.34.tgz", + "integrity": "sha512-yVRr/AAtPZlUvwEkrq7S3x7Z8/xCd97m2hLDaqdz6ucP2RKHsBjEqaUA2ebNv2SsZoPEi+ZD0dZbOB1u37tGCA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/node-config-provider": "^3.1.12", + "@smithy/protocol-http": "^4.1.8", + "@smithy/service-error-classification": "^3.0.11", + "@smithy/smithy-client": "^3.7.0", + "@smithy/types": "^3.7.2", + "@smithy/util-middleware": "^3.0.11", + "@smithy/util-retry": "^3.0.11", + "tslib": "^2.6.2", + "uuid": "^9.0.1" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "packages/core/node_modules/@aws-sdk/client-iot/node_modules/@smithy/node-http-handler": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/@smithy/node-http-handler/-/node-http-handler-3.3.3.tgz", + "integrity": "sha512-BrpZOaZ4RCbcJ2igiSNG16S+kgAc65l/2hmxWdmhyoGWHTLlzQzr06PXavJp9OBlPEG/sHlqdxjWmjzV66+BSQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/abort-controller": "^3.1.9", + "@smithy/protocol-http": "^4.1.8", + "@smithy/querystring-builder": "^3.0.11", + "@smithy/types": "^3.7.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "packages/core/node_modules/@aws-sdk/client-iot/node_modules/@smithy/protocol-http": { + "version": "4.1.8", + "resolved": "https://registry.npmjs.org/@smithy/protocol-http/-/protocol-http-4.1.8.tgz", + "integrity": "sha512-hmgIAVyxw1LySOwkgMIUN0kjN8TG9Nc85LJeEmEE/cNEe2rkHDUWhnJf2gxcSRFLWsyqWsrZGw40ROjUogg+Iw==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^3.7.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "packages/core/node_modules/@aws-sdk/client-iot/node_modules/@smithy/service-error-classification": { + "version": "3.0.11", + "resolved": "https://registry.npmjs.org/@smithy/service-error-classification/-/service-error-classification-3.0.11.tgz", + "integrity": "sha512-QnYDPkyewrJzCyaeI2Rmp7pDwbUETe+hU8ADkXmgNusO1bgHBH7ovXJiYmba8t0fNfJx75fE8dlM6SEmZxheog==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^3.7.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "packages/core/node_modules/@aws-sdk/client-iot/node_modules/@smithy/util-retry": { + "version": "3.0.11", + "resolved": "https://registry.npmjs.org/@smithy/util-retry/-/util-retry-3.0.11.tgz", + "integrity": "sha512-hJUC6W7A3DQgaee3Hp9ZFcOxVDZzmBIRBPlUAk8/fSOEl7pE/aX7Dci0JycNOnm9Mfr0KV2XjIlUOcGWXQUdVQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/service-error-classification": "^3.0.11", + "@smithy/types": "^3.7.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "packages/core/node_modules/@aws-sdk/client-iotsecuretunneling": { + "version": "3.693.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/client-iotsecuretunneling/-/client-iotsecuretunneling-3.693.0.tgz", + "integrity": "sha512-f9p5/TgVQsko0FlYIj9UKAVSfgPF4GgoKGVOI3Gx6XpynYwideGxItq3v0ExoAzpaohq6zRKleqA68o/T1TqXQ==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/sha256-browser": "5.2.0", + "@aws-crypto/sha256-js": "5.2.0", + "@aws-sdk/client-sso-oidc": "3.693.0", + "@aws-sdk/client-sts": "3.693.0", + "@aws-sdk/core": "3.693.0", + "@aws-sdk/credential-provider-node": "3.693.0", + "@aws-sdk/middleware-host-header": "3.693.0", + "@aws-sdk/middleware-logger": "3.693.0", + "@aws-sdk/middleware-recursion-detection": "3.693.0", + "@aws-sdk/middleware-user-agent": "3.693.0", + "@aws-sdk/region-config-resolver": "3.693.0", + "@aws-sdk/types": "3.692.0", + "@aws-sdk/util-endpoints": "3.693.0", + "@aws-sdk/util-user-agent-browser": "3.693.0", + "@aws-sdk/util-user-agent-node": "3.693.0", + "@smithy/config-resolver": "^3.0.11", + "@smithy/core": "^2.5.2", + "@smithy/fetch-http-handler": "^4.1.0", + "@smithy/hash-node": "^3.0.9", + "@smithy/invalid-dependency": "^3.0.9", + "@smithy/middleware-content-length": "^3.0.11", + "@smithy/middleware-endpoint": "^3.2.2", + "@smithy/middleware-retry": "^3.0.26", + "@smithy/middleware-serde": "^3.0.9", + "@smithy/middleware-stack": "^3.0.9", + "@smithy/node-config-provider": "^3.1.10", + "@smithy/node-http-handler": "^3.3.0", + "@smithy/protocol-http": "^4.1.6", + "@smithy/smithy-client": "^3.4.3", + "@smithy/types": "^3.7.0", + "@smithy/url-parser": "^3.0.9", + "@smithy/util-base64": "^3.0.0", + "@smithy/util-body-length-browser": "^3.0.0", + "@smithy/util-body-length-node": "^3.0.0", + "@smithy/util-defaults-mode-browser": "^3.0.26", + "@smithy/util-defaults-mode-node": "^3.0.26", + "@smithy/util-endpoints": "^2.1.5", + "@smithy/util-middleware": "^3.0.9", + "@smithy/util-retry": "^3.0.9", + "@smithy/util-utf8": "^3.0.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "packages/core/node_modules/@aws-sdk/client-iotsecuretunneling/node_modules/@smithy/fetch-http-handler": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/@smithy/fetch-http-handler/-/fetch-http-handler-4.1.3.tgz", + "integrity": "sha512-6SxNltSncI8s689nvnzZQc/dPXcpHQ34KUj6gR/HBroytKOd/isMG3gJF/zBE1TBmTT18TXyzhg3O3SOOqGEhA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/protocol-http": "^4.1.8", + "@smithy/querystring-builder": "^3.0.11", + "@smithy/types": "^3.7.2", + "@smithy/util-base64": "^3.0.0", + "tslib": "^2.6.2" + } + }, + "packages/core/node_modules/@aws-sdk/client-iotsecuretunneling/node_modules/@smithy/middleware-retry": { + "version": "3.0.34", + "resolved": "https://registry.npmjs.org/@smithy/middleware-retry/-/middleware-retry-3.0.34.tgz", + "integrity": "sha512-yVRr/AAtPZlUvwEkrq7S3x7Z8/xCd97m2hLDaqdz6ucP2RKHsBjEqaUA2ebNv2SsZoPEi+ZD0dZbOB1u37tGCA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/node-config-provider": "^3.1.12", + "@smithy/protocol-http": "^4.1.8", + "@smithy/service-error-classification": "^3.0.11", + "@smithy/smithy-client": "^3.7.0", + "@smithy/types": "^3.7.2", + "@smithy/util-middleware": "^3.0.11", + "@smithy/util-retry": "^3.0.11", + "tslib": "^2.6.2", + "uuid": "^9.0.1" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "packages/core/node_modules/@aws-sdk/client-iotsecuretunneling/node_modules/@smithy/node-http-handler": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/@smithy/node-http-handler/-/node-http-handler-3.3.3.tgz", + "integrity": "sha512-BrpZOaZ4RCbcJ2igiSNG16S+kgAc65l/2hmxWdmhyoGWHTLlzQzr06PXavJp9OBlPEG/sHlqdxjWmjzV66+BSQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/abort-controller": "^3.1.9", + "@smithy/protocol-http": "^4.1.8", + "@smithy/querystring-builder": "^3.0.11", + "@smithy/types": "^3.7.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "packages/core/node_modules/@aws-sdk/client-iotsecuretunneling/node_modules/@smithy/protocol-http": { + "version": "4.1.8", + "resolved": "https://registry.npmjs.org/@smithy/protocol-http/-/protocol-http-4.1.8.tgz", + "integrity": "sha512-hmgIAVyxw1LySOwkgMIUN0kjN8TG9Nc85LJeEmEE/cNEe2rkHDUWhnJf2gxcSRFLWsyqWsrZGw40ROjUogg+Iw==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^3.7.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "packages/core/node_modules/@aws-sdk/client-iotsecuretunneling/node_modules/@smithy/service-error-classification": { + "version": "3.0.11", + "resolved": "https://registry.npmjs.org/@smithy/service-error-classification/-/service-error-classification-3.0.11.tgz", + "integrity": "sha512-QnYDPkyewrJzCyaeI2Rmp7pDwbUETe+hU8ADkXmgNusO1bgHBH7ovXJiYmba8t0fNfJx75fE8dlM6SEmZxheog==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^3.7.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "packages/core/node_modules/@aws-sdk/client-iotsecuretunneling/node_modules/@smithy/util-retry": { + "version": "3.0.11", + "resolved": "https://registry.npmjs.org/@smithy/util-retry/-/util-retry-3.0.11.tgz", + "integrity": "sha512-hJUC6W7A3DQgaee3Hp9ZFcOxVDZzmBIRBPlUAk8/fSOEl7pE/aX7Dci0JycNOnm9Mfr0KV2XjIlUOcGWXQUdVQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/service-error-classification": "^3.0.11", + "@smithy/types": "^3.7.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, "packages/core/node_modules/@aws-sdk/client-sso": { "version": "3.693.0", "license": "Apache-2.0", diff --git a/packages/core/package.json b/packages/core/package.json index fb82cb9c9d7..ced5c2981f5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -539,6 +539,7 @@ "@types/whatwg-url": "^11.0.4", "@types/xml2js": "^0.4.11", "@vue/compiler-sfc": "^3.3.2", + "aws-sdk-client-mock": "^4.1.0", "c8": "^9.0.0", "circular-dependency-plugin": "^5.2.2", "css-loader": "^6.10.0", @@ -580,6 +581,8 @@ "@aws-sdk/client-ec2": "<3.731.0", "@aws-sdk/client-glue": "^3.852.0", "@aws-sdk/client-iam": "<3.731.0", + "@aws-sdk/client-iot": "~3.693.0", + "@aws-sdk/client-iotsecuretunneling": "~3.693.0", "@aws-sdk/client-lambda": "<3.731.0", "@aws-sdk/client-s3": "<3.731.0", "@aws-sdk/client-s3-control": "^3.830.0", diff --git a/packages/core/src/awsService/iot/commands/attachCertificate.ts b/packages/core/src/awsService/iot/commands/attachCertificate.ts index be9edd03d89..684160dafbf 100644 --- a/packages/core/src/awsService/iot/commands/attachCertificate.ts +++ b/packages/core/src/awsService/iot/commands/attachCertificate.ts @@ -12,7 +12,7 @@ import { createQuickPick, DataQuickPickItem } from '../../../shared/ui/pickerPro import { PromptResult } from '../../../shared/ui/prompter' import { IotClient } from '../../../shared/clients/iotClient' import { isValidResponse } from '../../../shared/wizards/wizard' -import { Iot } from 'aws-sdk' +import { Certificate, ListCertificatesResponse } from '@aws-sdk/client-iot' export type CertGen = typeof getCertList @@ -53,8 +53,8 @@ export async function attachCertificateCommand(node: IotThingNode, promptFun = p /** * Prompts the user to pick a certificate to attach. */ -async function promptForCert(iot: IotClient, certFetch: CertGen): Promise> { - const placeHolder: DataQuickPickItem = { +async function promptForCert(iot: IotClient, certFetch: CertGen): Promise> { + const placeHolder: DataQuickPickItem = { label: 'No certificates found', data: undefined, } @@ -71,10 +71,10 @@ async function promptForCert(iot: IotClient, certFetch: CertGen): Promise = new Map() - private iotSTClientCache: Map = new Map() + private iotSTClientCache: Map = new Map() constructor() {} @@ -97,9 +104,9 @@ export class LdkClient { return this.lambdaClientCache.get(region)! } - private async getIoTSTClient(region: string): Promise { + private getIoTSTClient(region: string): IoTSecureTunnelingClient { if (!this.iotSTClientCache.has(region)) { - this.iotSTClientCache.set(region, await getIoTSTClientWithAgent(region)) + this.iotSTClientCache.set(region, getIoTSTClientWithAgent(region)) } return this.iotSTClientCache.get(region)! } @@ -124,13 +131,13 @@ export class LdkClient { const vscodeUuid = getClientId(globals.globalState) // Create IoTSecureTunneling client - const iotSecureTunneling = await this.getIoTSTClient(region) + const iotSecureTunneling = this.getIoTSTClient(region) // Define tunnel identifier const tunnelIdentifier = `RemoteDebugging+${vscodeUuid}` const timeoutInMinutes = 720 // List existing tunnels - const listTunnelsResponse = await iotSecureTunneling.listTunnels({}).promise() + const listTunnelsResponse = await iotSecureTunneling.send(new ListTunnelsCommand({})) // Find tunnel with our identifier const existingTunnel = listTunnelsResponse.tunnelSummaries?.find( @@ -150,20 +157,20 @@ export class LdkClient { return rotateResponse } else { // Close tunnel if less than 15 minutes remaining - await iotSecureTunneling - .closeTunnel({ + await iotSecureTunneling.send( + new CloseTunnelCommand({ tunnelId: existingTunnel.tunnelId, delete: false, }) - .promise() + ) getLogger().info(`Closed tunnel ${existingTunnel.tunnelId} with less than 15 minutes remaining`) } } // Create new tunnel - const openTunnelResponse = await iotSecureTunneling - .openTunnel({ + const openTunnelResponse = await iotSecureTunneling.send( + new OpenTunnelCommand({ description: tunnelIdentifier, timeoutConfig: { maxLifetimeTimeoutMinutes: timeoutInMinutes, // 12 hours @@ -172,7 +179,7 @@ export class LdkClient { services: ['WSS'], }, }) - .promise() + ) getLogger().info(`Created new tunnel with ID: ${openTunnelResponse.tunnelId}`) @@ -189,13 +196,13 @@ export class LdkClient { // Refresh tunnel tokens async refreshTunnelTokens(tunnelId: string, region: string): Promise { try { - const iotSecureTunneling = await this.getIoTSTClient(region) - const rotateResponse = await iotSecureTunneling - .rotateTunnelAccessToken({ + const iotSecureTunneling = this.getIoTSTClient(region) + const rotateResponse = await iotSecureTunneling.send( + new RotateTunnelAccessTokenCommand({ tunnelId: tunnelId, clientMode: 'ALL', }) - .promise() + ) return { tunnelID: tunnelId, diff --git a/packages/core/src/lambda/remoteDebugging/utils.ts b/packages/core/src/lambda/remoteDebugging/utils.ts index 7d09fb46f49..8f2ea862556 100644 --- a/packages/core/src/lambda/remoteDebugging/utils.ts +++ b/packages/core/src/lambda/remoteDebugging/utils.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import IoTSecureTunneling from 'aws-sdk/clients/iotsecuretunneling' +import { IoTSecureTunnelingClient } from '@aws-sdk/client-iotsecuretunneling' import { DefaultLambdaClient } from '../../shared/clients/lambdaClient' import { getUserAgent } from '../../shared/telemetry/util' import globals from '../../shared/extensionGlobals' @@ -29,13 +29,14 @@ export function getLambdaUserAgent(): string { return `${getUserAgent({ includePlatform: true, includeClientId: true })}` } -export function getIoTSTClientWithAgent(region: string): Promise { +export function getIoTSTClientWithAgent(region: string): IoTSecureTunnelingClient { const customUserAgent = `${customUserAgentBase} ${getUserAgent({ includePlatform: true, includeClientId: true })}` - return globals.sdkClientBuilder.createAwsService( - IoTSecureTunneling, - { - customUserAgent, + return globals.sdkClientBuilderV3.createAwsService({ + serviceClient: IoTSecureTunnelingClient, + clientOptions: { + userAgent: [[customUserAgent]], + region, }, - region - ) + userAgent: false, + }) } diff --git a/packages/core/src/shared/clients/iotClient.ts b/packages/core/src/shared/clients/iotClient.ts index 45b9cbd4e4f..fc5581fffa4 100644 --- a/packages/core/src/shared/clients/iotClient.ts +++ b/packages/core/src/shared/clients/iotClient.ts @@ -4,7 +4,70 @@ */ import * as _ from 'lodash' -import { Iot } from 'aws-sdk' +import { + AttachPolicyCommand, + AttachPolicyRequest, + AttachThingPrincipalCommand, + AttachThingPrincipalRequest, + CertificateDescription, + CreateKeysAndCertificateCommand, + CreateKeysAndCertificateRequest, + CreateKeysAndCertificateResponse, + CreatePolicyCommand, + CreatePolicyRequest, + CreatePolicyResponse, + CreatePolicyVersionCommand, + CreatePolicyVersionRequest, + CreateThingCommand, + CreateThingRequest, + CreateThingResponse, + DeleteCertificateCommand, + DeleteCertificateRequest, + DeletePolicyCommand, + DeletePolicyRequest, + DeletePolicyVersionCommand, + DeletePolicyVersionRequest, + DeleteThingCommand, + DeleteThingRequest, + DescribeCertificateCommand, + DescribeCertificateRequest, + DescribeCertificateResponse, + DescribeEndpointCommand, + DetachPolicyCommand, + DetachPolicyRequest, + DetachThingPrincipalCommand, + DetachThingPrincipalRequest, + GetPolicyVersionCommand, + GetPolicyVersionRequest, + GetPolicyVersionResponse, + IoTClient, + ListCertificatesCommand, + ListCertificatesRequest, + ListCertificatesResponse, + ListPoliciesCommand, + ListPoliciesRequest, + ListPoliciesResponse, + ListPolicyVersionsCommand, + ListPolicyVersionsRequest, + ListPrincipalPoliciesCommand, + ListPrincipalPoliciesRequest, + ListPrincipalPoliciesResponse, + ListPrincipalThingsCommand, + ListPrincipalThingsRequest, + ListTargetsForPolicyCommand, + ListTargetsForPolicyRequest, + ListThingPrincipalsCommand, + ListThingPrincipalsRequest, + ListThingPrincipalsResponse, + ListThingsCommand, + ListThingsRequest, + ListThingsResponse, + PolicyVersion, + SetDefaultPolicyVersionCommand, + SetDefaultPolicyVersionRequest, + UpdateCertificateCommand, + UpdateCertificateRequest, +} from '@aws-sdk/client-iot' import { parse } from '@aws-sdk/util-arn-parser' import { getLogger } from '../logger/logger' import { InterfaceNoSymbol } from '../utilities/tsUtils' @@ -30,14 +93,14 @@ const iotServiceArn = 'iot' const certArnResourcePattern = /cert\/(\w+)/ export interface ListThingCertificatesResponse { - readonly certificates: Iot.CertificateDescription[] + readonly certificates: CertificateDescription[] readonly nextToken: string | undefined } export class DefaultIotClient { public constructor( private readonly regionCode: string, - private readonly iotProvider: (regionCode: string) => Promise = createSdkClient + private readonly iotProvider: (regionCode: string) => IoTClient = createSdkClient ) {} /** @@ -45,16 +108,16 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async listThings(request?: Iot.ListThingsRequest): Promise { + public async listThings(request?: ListThingsRequest): Promise { getLogger().debug('ListThings called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - const output: Iot.ListThingsResponse = await iot - .listThings({ + const output: ListThingsResponse = await iot.send( + new ListThingsCommand({ maxResults: request?.maxResults ?? defaultMaxThings, nextToken: request?.nextToken, }) - .promise() + ) getLogger().debug('ListThings returned response: %O', output) return output @@ -65,11 +128,11 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async createThing(request: Iot.CreateThingRequest): Promise { + public async createThing(request: CreateThingRequest): Promise { getLogger().debug('CreateThing called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - const output: Iot.CreateThingResponse = await iot.createThing({ thingName: request.thingName }).promise() + const output: CreateThingResponse = await iot.send(new CreateThingCommand({ thingName: request.thingName })) getLogger().debug('CreateThing returned response: %O', output) return output @@ -80,11 +143,11 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async deleteThing(request: Iot.DeleteThingRequest): Promise { + public async deleteThing(request: DeleteThingRequest): Promise { getLogger().debug('DeleteThing called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - await iot.deleteThing({ thingName: request.thingName }).promise() + await iot.send(new DeleteThingCommand({ thingName: request.thingName })) getLogger().debug('DeleteThing successful') } @@ -94,17 +157,17 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async listCertificates(request: Iot.ListCertificatesRequest): Promise { + public async listCertificates(request: ListCertificatesRequest): Promise { getLogger().debug('ListCertificates called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - const output: Iot.ListCertificatesResponse = await iot - .listCertificates({ + const output: ListCertificatesResponse = await iot.send( + new ListCertificatesCommand({ pageSize: request.pageSize ?? defaultMaxThings, marker: request.marker, ascendingOrder: request.ascendingOrder, }) - .promise() + ) getLogger().debug('ListCertificates returned response: %O', output) return output @@ -118,18 +181,16 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async listThingPrincipals( - request: Iot.ListThingPrincipalsRequest - ): Promise { - const iot = await this.iotProvider(this.regionCode) + public async listThingPrincipals(request: ListThingPrincipalsRequest): Promise { + const iot = this.iotProvider(this.regionCode) - const output: Iot.ListThingPrincipalsResponse = await iot - .listThingPrincipals({ + const output: ListThingPrincipalsResponse = await iot.send( + new ListThingPrincipalsCommand({ thingName: request.thingName, maxResults: request.maxResults ?? defaultMaxThings, nextToken: request.nextToken, }) - .promise() + ) return output } @@ -138,12 +199,10 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - private async describeCertificate( - request: Iot.DescribeCertificateRequest - ): Promise { - const iot = await this.iotProvider(this.regionCode) + private async describeCertificate(request: DescribeCertificateRequest): Promise { + const iot = this.iotProvider(this.regionCode) - const output: Iot.DescribeCertificateResponse = await iot.describeCertificate(request).promise() + const output: DescribeCertificateResponse = await iot.send(new DescribeCertificateCommand(request)) return output } @@ -158,13 +217,11 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async listThingCertificates( - request: Iot.ListThingPrincipalsRequest - ): Promise { + public async listThingCertificates(request: ListThingPrincipalsRequest): Promise { getLogger().debug('ListThingCertificates called with request: %O', request) const output = await this.listThingPrincipals(request) - const iotPrincipals: Iot.Principal[] = output.principals ?? [] + const iotPrincipals: string[] = output.principals ?? [] const nextToken = output.nextToken const describedCerts = iotPrincipals.map(async (iotPrincipal) => { @@ -179,7 +236,7 @@ export class DefaultIotClient { const resolvedCerts = (await Promise.all(describedCerts)) .filter((cert) => cert?.certificateDescription !== undefined) - .map((cert) => cert?.certificateDescription as Iot.CertificateDescription) + .map((cert) => cert?.certificateDescription as CertificateDescription) const response: ListThingCertificatesResponse = { certificates: resolvedCerts, nextToken: nextToken } getLogger().debug('ListThingCertificates returned response: %O', response) @@ -194,18 +251,18 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async listThingsForCert(request: Iot.ListPrincipalThingsRequest): Promise { + public async listThingsForCert(request: ListPrincipalThingsRequest): Promise { getLogger().debug('ListThingsForCert called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - const output = await iot - .listPrincipalThings({ + const output = await iot.send( + new ListPrincipalThingsCommand({ maxResults: request.maxResults ?? defaultMaxThings, nextToken: request.nextToken, principal: request.principal, }) - .promise() - const iotThings: Iot.ThingName[] = output.things ?? [] + ) + const iotThings: string[] = output.things ?? [] getLogger().debug('ListThingsForCert returned response: %O', iotThings) return iotThings @@ -217,12 +274,12 @@ export class DefaultIotClient { * @throws Error if there is an error calling IoT. */ public async createCertificateAndKeys( - request: Iot.CreateKeysAndCertificateRequest - ): Promise { + request: CreateKeysAndCertificateRequest + ): Promise { getLogger().debug('CreateCertificate called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - const output: Iot.CreateKeysAndCertificateResponse = await iot.createKeysAndCertificate(request).promise() + const output: CreateKeysAndCertificateResponse = await iot.send(new CreateKeysAndCertificateCommand(request)) getLogger().debug('CreateCertificate succeeded') return output @@ -233,11 +290,13 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async updateCertificate(request: Iot.UpdateCertificateRequest): Promise { + public async updateCertificate(request: UpdateCertificateRequest): Promise { getLogger().debug('UpdateCertificate called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - await iot.updateCertificate({ certificateId: request.certificateId, newStatus: request.newStatus }).promise() + await iot.send( + new UpdateCertificateCommand({ certificateId: request.certificateId, newStatus: request.newStatus }) + ) getLogger().debug('UpdateCertificate successful') } @@ -251,11 +310,11 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async deleteCertificate(request: Iot.DeleteCertificateRequest): Promise { + public async deleteCertificate(request: DeleteCertificateRequest): Promise { getLogger().debug('DeleteCertificate called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - await iot.deleteCertificate(request).promise() + await iot.send(new DeleteCertificateCommand(request)) getLogger().debug('DeleteCertificate successful') } @@ -265,11 +324,11 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async attachThingPrincipal(request: Iot.AttachThingPrincipalRequest): Promise { + public async attachThingPrincipal(request: AttachThingPrincipalRequest): Promise { getLogger().debug('AttachThingPrincipal called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - await iot.attachThingPrincipal({ thingName: request.thingName, principal: request.principal }).promise() + await iot.send(new AttachThingPrincipalCommand({ thingName: request.thingName, principal: request.principal })) getLogger().debug('AttachThingPrincipal successful') } @@ -279,11 +338,11 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async detachThingPrincipal(request: Iot.DetachThingPrincipalRequest): Promise { + public async detachThingPrincipal(request: DetachThingPrincipalRequest): Promise { getLogger().debug('DetachThingPrincipal called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - await iot.detachThingPrincipal({ thingName: request.thingName, principal: request.principal }).promise() + await iot.send(new DetachThingPrincipalCommand({ thingName: request.thingName, principal: request.principal })) getLogger().debug('DetachThingPrincipal successful') } @@ -293,17 +352,17 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async listPolicies(request: Iot.ListPoliciesRequest): Promise { + public async listPolicies(request: ListPoliciesRequest): Promise { getLogger().debug('ListPolicies called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - const output: Iot.ListPoliciesResponse = await iot - .listPolicies({ + const output: ListPoliciesResponse = await iot.send( + new ListPoliciesCommand({ pageSize: request.pageSize ?? defaultMaxThings, marker: request.marker, ascendingOrder: request.ascendingOrder, }) - .promise() + ) getLogger().debug('ListPolicies returned response: %O', output) return output @@ -314,18 +373,18 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async listPrincipalPolicies(request: Iot.ListPrincipalPoliciesRequest): Promise { + public async listPrincipalPolicies(request: ListPrincipalPoliciesRequest): Promise { getLogger().debug('ListPrincipalPolicies called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - const output: Iot.ListPrincipalPoliciesResponse = await iot - .listPrincipalPolicies({ + const output: ListPrincipalPoliciesResponse = await iot.send( + new ListPrincipalPoliciesCommand({ principal: request.principal, pageSize: request.pageSize ?? defaultMaxThings, marker: request.marker, ascendingOrder: request.ascendingOrder, }) - .promise() + ) getLogger().debug('ListPrincipalPolicies returned response: %O', output) return output @@ -339,18 +398,18 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async listPolicyTargets(request: Iot.ListTargetsForPolicyRequest): Promise { + public async listPolicyTargets(request: ListTargetsForPolicyRequest): Promise { getLogger().debug('ListPolicyTargets called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - const output = await iot - .listTargetsForPolicy({ + const output = await iot.send( + new ListTargetsForPolicyCommand({ pageSize: request.pageSize ?? defaultMaxThings, marker: request.marker, policyName: request.policyName, }) - .promise() - const arns: Iot.Target[] = output.targets ?? [] + ) + const arns: string[] = output.targets ?? [] getLogger().debug('ListPolicyTargets returned response: %O', arns) return arns @@ -361,11 +420,11 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async attachPolicy(request: Iot.AttachPolicyRequest): Promise { + public async attachPolicy(request: AttachPolicyRequest): Promise { getLogger().debug('AttachPolicy called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - await iot.attachPolicy({ policyName: request.policyName, target: request.target }).promise() + await iot.send(new AttachPolicyCommand({ policyName: request.policyName, target: request.target })) getLogger().debug('AttachPolicy successful') } @@ -375,11 +434,11 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async detachPolicy(request: Iot.DetachPolicyRequest): Promise { + public async detachPolicy(request: DetachPolicyRequest): Promise { getLogger().debug('DetachPolicy called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - await iot.detachPolicy({ policyName: request.policyName, target: request.target }).promise() + await iot.send(new DetachPolicyCommand({ policyName: request.policyName, target: request.target })) getLogger().debug('DetachPolicy successful') } @@ -389,11 +448,11 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async createPolicy(request: Iot.CreatePolicyRequest): Promise { + public async createPolicy(request: CreatePolicyRequest): Promise { getLogger().debug('CreatePolicy called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - const output: Iot.CreatePolicyResponse = await iot.createPolicy(request).promise() + const output: CreatePolicyResponse = await iot.send(new CreatePolicyCommand(request)) getLogger().info(`Created policy: ${output.policyArn}`) getLogger().debug('CreatePolicy successful') @@ -408,11 +467,11 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async deletePolicy(request: Iot.DeletePolicyRequest): Promise { + public async deletePolicy(request: DeletePolicyRequest): Promise { getLogger().debug('DeletePolicy called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - await iot.deletePolicy({ policyName: request.policyName }).promise() + await iot.send(new DeletePolicyCommand({ policyName: request.policyName })) getLogger().debug('DeletePolicy successful') } @@ -424,9 +483,9 @@ export class DefaultIotClient { */ public async getEndpoint(): Promise { getLogger().debug('GetEndpoint called') - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - const output = await iot.describeEndpoint({ endpointType: iotEndpointType }).promise() + const output = await iot.send(new DescribeEndpointCommand({ endpointType: iotEndpointType })) if (!output.endpointAddress) { throw new Error('Failed to retrieve endpoint') } @@ -440,10 +499,10 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async *listPolicyVersions(request: Iot.ListPolicyVersionsRequest): AsyncIterableIterator { - const iot = await this.iotProvider(this.regionCode) + public async *listPolicyVersions(request: ListPolicyVersionsRequest): AsyncIterableIterator { + const iot = this.iotProvider(this.regionCode) - const response = await iot.listPolicyVersions(request).promise() + const response = await iot.send(new ListPolicyVersionsCommand(request)) if (response.policyVersions) { yield* response.policyVersions @@ -455,11 +514,11 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async createPolicyVersion(request: Iot.CreatePolicyVersionRequest): Promise { + public async createPolicyVersion(request: CreatePolicyVersionRequest): Promise { getLogger().debug('CreatePolicyVersion called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - const output = await iot.createPolicyVersion(request).promise() + const output = await iot.send(new CreatePolicyVersionCommand(request)) getLogger().info(`Created new version ${output.policyVersionId} of ${request.policyName}`) getLogger().debug('CreatePolicyVersion successful') @@ -474,11 +533,11 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async deletePolicyVersion(request: Iot.DeletePolicyVersionRequest): Promise { + public async deletePolicyVersion(request: DeletePolicyVersionRequest): Promise { getLogger().debug('DeletePolicyVersion called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - await iot.deletePolicyVersion(request).promise() + await iot.send(new DeletePolicyVersionCommand(request)) getLogger().debug('DeletePolicyVersion successful') } @@ -488,11 +547,11 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async setDefaultPolicyVersion(request: Iot.SetDefaultPolicyVersionRequest): Promise { + public async setDefaultPolicyVersion(request: SetDefaultPolicyVersionRequest): Promise { getLogger().debug('SetDefaultPolicyVersion called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - await iot.setDefaultPolicyVersion(request).promise() + await iot.send(new SetDefaultPolicyVersionCommand(request)) getLogger().debug('SetDefaultPolicyVersion successful') } @@ -502,17 +561,20 @@ export class DefaultIotClient { * * @throws Error if there is an error calling IoT. */ - public async getPolicyVersion(request: Iot.GetPolicyVersionRequest): Promise { + public async getPolicyVersion(request: GetPolicyVersionRequest): Promise { getLogger().debug('GetPolicyVersion called with request: %O', request) - const iot = await this.iotProvider(this.regionCode) + const iot = this.iotProvider(this.regionCode) - const output: Iot.GetPolicyVersionResponse = await iot.getPolicyVersion(request).promise() + const output: GetPolicyVersionResponse = await iot.send(new GetPolicyVersionCommand(request)) getLogger().debug('GetPolicyVersion successful') return output } } -async function createSdkClient(regionCode: string): Promise { - return await globals.sdkClientBuilder.createAwsService(Iot, undefined, regionCode) +function createSdkClient(regionCode: string): IoTClient { + return globals.sdkClientBuilderV3.createAwsService({ + serviceClient: IoTClient, + clientOptions: { region: regionCode }, + }) } diff --git a/packages/core/src/test/awsService/iot/commands/attachCertificate.test.ts b/packages/core/src/test/awsService/iot/commands/attachCertificate.test.ts index f0796e9cc60..840c375a80c 100644 --- a/packages/core/src/test/awsService/iot/commands/attachCertificate.test.ts +++ b/packages/core/src/test/awsService/iot/commands/attachCertificate.test.ts @@ -5,7 +5,7 @@ import * as vscode from 'vscode' import * as sinon from 'sinon' -import { Iot } from 'aws-sdk' +import { Certificate } from '@aws-sdk/client-iot' import { attachCertificateCommand, CertGen } from '../../../../awsService/iot/commands/attachCertificate' import { IotThingFolderNode } from '../../../../awsService/iot/explorer/iotThingFolderNode' import { IotThingNode } from '../../../../awsService/iot/explorer/iotThingNode' @@ -19,22 +19,22 @@ import assert from 'assert' describe('attachCertCommand', function () { const thingName = 'iot-thing' let iot: IotClient - let certs: Iot.Certificate[] + let certs: Certificate[] let thingNode: IotThingNode let selection: number = 0 let sandbox: sinon.SinonSandbox let spyExecuteCommand: sinon.SinonSpy - const prompt: (iot: IotClient, certFetch: CertGen) => Promise> = async ( + const prompt: (iot: IotClient, certFetch: CertGen) => Promise> = async ( iot, certFetch ) => { const iterable = certFetch(iot) - const responses: DataQuickPickItem[] = [] + const responses: DataQuickPickItem[] = [] for await (const response of iterable) { responses.push(...response) } - return selection > -1 ? (responses[selection].data as Iot.Certificate) : undefined + return selection > -1 ? (responses[selection].data as Certificate) : undefined } beforeEach(function () { diff --git a/packages/core/src/test/lambda/remoteDebugging/ldkClient.test.ts b/packages/core/src/test/lambda/remoteDebugging/ldkClient.test.ts index 91f99aa0409..24c9b956e70 100644 --- a/packages/core/src/test/lambda/remoteDebugging/ldkClient.test.ts +++ b/packages/core/src/test/lambda/remoteDebugging/ldkClient.test.ts @@ -12,12 +12,23 @@ import * as utils from '../../../lambda/remoteDebugging/utils' import * as telemetryUtil from '../../../shared/telemetry/util' import globals from '../../../shared/extensionGlobals' import { createMockFunctionConfig, createMockProgress } from './testUtils' +import { + IoTSecureTunnelingClient, + IoTSecureTunnelingClientResolvedConfig, + ListTunnelsCommand, + OpenTunnelCommand, + RotateTunnelAccessTokenCommand, + ServiceInputTypes, + ServiceOutputTypes, + TunnelStatus, +} from '@aws-sdk/client-iotsecuretunneling' +import { AwsStub, mockClient } from 'aws-sdk-client-mock' describe('LdkClient', () => { let sandbox: sinon.SinonSandbox let ldkClient: LdkClient let mockLambdaClient: any - let mockIoTSTClient: any + let mockIoTSTClient: AwsStub let mockLocalProxy: any beforeEach(() => { @@ -32,15 +43,8 @@ describe('LdkClient', () => { } sandbox.stub(utils, 'getLambdaClientWithAgent').returns(mockLambdaClient) - // Mock IoT ST client with proper promise structure - const createPromiseStub = () => sandbox.stub() - mockIoTSTClient = { - listTunnels: sandbox.stub().returns({ promise: createPromiseStub() }), - openTunnel: sandbox.stub().returns({ promise: createPromiseStub() }), - closeTunnel: sandbox.stub().returns({ promise: createPromiseStub() }), - rotateTunnelAccessToken: sandbox.stub().returns({ promise: createPromiseStub() }), - } - sandbox.stub(utils, 'getIoTSTClientWithAgent').resolves(mockIoTSTClient) + mockIoTSTClient = mockClient(IoTSecureTunnelingClient) + sandbox.stub(utils, 'getIoTSTClientWithAgent').returns(mockIoTSTClient as any) // Mock LocalProxy mockLocalProxy = { @@ -105,8 +109,8 @@ describe('LdkClient', () => { describe('createOrReuseTunnel()', () => { it('should create new tunnel when none exists', async () => { - mockIoTSTClient.listTunnels().promise.resolves({ tunnelSummaries: [] }) - mockIoTSTClient.openTunnel().promise.resolves({ + mockIoTSTClient.on(ListTunnelsCommand).resolves({ tunnelSummaries: [] }) + mockIoTSTClient.on(OpenTunnelCommand).resolves({ tunnelId: 'tunnel-123', sourceAccessToken: 'source-token', destinationAccessToken: 'dest-token', @@ -118,20 +122,24 @@ describe('LdkClient', () => { assert.strictEqual(result?.tunnelID, 'tunnel-123') assert.strictEqual(result?.sourceToken, 'source-token') assert.strictEqual(result?.destinationToken, 'dest-token') - assert(mockIoTSTClient.listTunnels.called, 'Should list existing tunnels') - assert(mockIoTSTClient.openTunnel.called, 'Should create new tunnel') + assert.strictEqual( + mockIoTSTClient.commandCalls(ListTunnelsCommand).length, + 1, + 'Should list existing tunnels' + ) + assert.strictEqual(mockIoTSTClient.commandCalls(OpenTunnelCommand).length, 1, 'Should create new tunnel') }) it('should reuse existing tunnel with sufficient time remaining', async () => { const existingTunnel = { tunnelId: 'existing-tunnel', description: 'RemoteDebugging+test-client-id', - status: 'OPEN', + status: TunnelStatus.OPEN, createdAt: new Date(Date.now() - 60 * 60 * 1000), // 1 hour ago } - mockIoTSTClient.listTunnels().promise.resolves({ tunnelSummaries: [existingTunnel] }) - mockIoTSTClient.rotateTunnelAccessToken().promise.resolves({ + mockIoTSTClient.on(ListTunnelsCommand).resolves({ tunnelSummaries: [existingTunnel] }) + mockIoTSTClient.on(RotateTunnelAccessTokenCommand).resolves({ sourceAccessToken: 'rotated-source-token', destinationAccessToken: 'rotated-dest-token', }) @@ -145,8 +153,8 @@ describe('LdkClient', () => { }) it('should handle tunnel creation errors', async () => { - mockIoTSTClient.listTunnels().promise.resolves({ tunnelSummaries: [] }) - mockIoTSTClient.openTunnel().promise.rejects(new Error('Tunnel creation failed')) + mockIoTSTClient.on(ListTunnelsCommand).resolves({ tunnelSummaries: [] }) + mockIoTSTClient.on(OpenTunnelCommand).rejects(new Error('Tunnel creation failed')) await assert.rejects( async () => await ldkClient.createOrReuseTunnel('us-east-1'), @@ -158,7 +166,7 @@ describe('LdkClient', () => { describe('refreshTunnelTokens()', () => { it('should refresh tunnel tokens successfully', async () => { - mockIoTSTClient.rotateTunnelAccessToken().promise.resolves({ + mockIoTSTClient.on(RotateTunnelAccessTokenCommand).resolves({ sourceAccessToken: 'new-source-token', destinationAccessToken: 'new-dest-token', }) @@ -172,7 +180,7 @@ describe('LdkClient', () => { }) it('should handle token refresh errors', async () => { - mockIoTSTClient.rotateTunnelAccessToken().promise.rejects(new Error('Token refresh failed')) + mockIoTSTClient.on(RotateTunnelAccessTokenCommand).rejects(new Error('Token refresh failed')) await assert.rejects( async () => await ldkClient.refreshTunnelTokens('tunnel-123', 'us-east-1'), diff --git a/packages/core/src/test/shared/clients/defaultIotClient.test.ts b/packages/core/src/test/shared/clients/defaultIotClient.test.ts index a42e6a691af..ebeae95cee2 100644 --- a/packages/core/src/test/shared/clients/defaultIotClient.test.ts +++ b/packages/core/src/test/shared/clients/defaultIotClient.test.ts @@ -4,10 +4,80 @@ */ import assert from 'assert' -import { AWSError, Request, Iot, Endpoint, Config } from 'aws-sdk' +import { AWSError } from 'aws-sdk' +import { + AttachPolicyCommand, + AttachPolicyRequest, + AttachThingPrincipalCommand, + AttachThingPrincipalRequest, + CreateKeysAndCertificateCommand, + CreateKeysAndCertificateRequest, + CreateKeysAndCertificateResponse, + CreatePolicyCommand, + CreatePolicyRequest, + CreatePolicyResponse, + CreatePolicyVersionCommand, + CreatePolicyVersionRequest, + CreatePolicyVersionResponse, + CreateThingCommand, + CreateThingResponse, + DeleteCertificateCommand, + DeleteCertificateRequest, + DeletePolicyCommand, + DeletePolicyRequest, + DeletePolicyVersionCommand, + DeletePolicyVersionRequest, + DeleteThingCommand, + DeleteThingRequest, + DeleteThingResponse, + DescribeCertificateCommand, + DescribeCertificateRequest, + DescribeCertificateResponse, + DescribeEndpointCommand, + DescribeEndpointRequest, + DescribeEndpointResponse, + DetachPolicyCommand, + DetachPolicyRequest, + DetachThingPrincipalCommand, + DetachThingPrincipalRequest, + GetPolicyVersionCommand, + GetPolicyVersionRequest, + GetPolicyVersionResponse, + IoTClient, + IoTClientResolvedConfig, + ListCertificatesCommand, + ListCertificatesRequest, + ListCertificatesResponse, + ListPoliciesCommand, + ListPoliciesRequest, + ListPoliciesResponse, + ListPolicyVersionsCommand, + ListPolicyVersionsRequest, + ListPolicyVersionsResponse, + ListPrincipalPoliciesCommand, + ListPrincipalPoliciesRequest, + ListPrincipalThingsCommand, + ListPrincipalThingsRequest, + ListPrincipalThingsResponse, + ListTargetsForPolicyCommand, + ListTargetsForPolicyRequest, + ListTargetsForPolicyResponse, + ListThingPrincipalsCommand, + ListThingPrincipalsRequest, + ListThingPrincipalsResponse, + ListThingsCommand, + ListThingsRequest, + ListThingsResponse, + PolicyVersion, + ServiceInputTypes, + ServiceOutputTypes, + SetDefaultPolicyVersionCommand, + SetDefaultPolicyVersionRequest, + UpdateCertificateCommand, + UpdateCertificateRequest, +} from '@aws-sdk/client-iot' import { DefaultIotClient, ListThingCertificatesResponse } from '../../../shared/clients/iotClient' -import { Stub, stub } from '../../utilities/stubber' -import sinon from 'sinon' +import { AwsStub, mockClient } from 'aws-sdk-client-mock' class FakeAwsError extends Error { public region: string = 'us-west-2' @@ -26,55 +96,33 @@ describe('DefaultIotClient', function () { const marker = nextToken const maxResults = 10 const pageSize = maxResults - let mockIot: Stub + let mockIot: AwsStub beforeEach(function () { - mockIot = stub(Iot, { - config: stub(Config), - apiVersions: [], - endpoint: stub(Endpoint, { - host: '', - hostname: '', - href: '', - port: 0, - protocol: '', - }), - }) + mockIot = mockClient(IoTClient) }) const error: AWSError = new FakeAwsError('Expected failure') as AWSError - function success(output?: T): Request { - return { - promise: () => Promise.resolve(output), - } as Request - } - - function failure(): Request { - return { - promise: () => Promise.reject(error), - } as Request - } - function createClient({ regionCode = region }: { regionCode?: string } = {}): DefaultIotClient { - return new DefaultIotClient(regionCode, () => Promise.resolve(mockIot)) + return new DefaultIotClient(regionCode, () => new IoTClient()) } /* Functions that create or retrieve resources. */ describe('createThing', function () { - const expectedResponse: Iot.CreateThingResponse = { thingName: thingName, thingArn: 'arn' } + const expectedResponse: CreateThingResponse = { thingName: thingName, thingArn: 'arn' } it('creates a thing', async function () { - mockIot.createThing.returns(success(expectedResponse)) + mockIot.on(CreateThingCommand).resolves(expectedResponse) const response = await createClient().createThing({ thingName }) - assert(mockIot.createThing.calledOnceWithExactly) + assert.strictEqual(mockIot.commandCalls(CreateThingCommand).length, 1) assert.deepStrictEqual(response, expectedResponse) }) it('throws an Error on failure', async function () { - mockIot.createThing.returns(failure()) + mockIot.on(CreateThingCommand).rejects(error) await assert.rejects(createClient().createThing({ thingName }), error) }) @@ -82,8 +130,8 @@ describe('DefaultIotClient', function () { describe('createCertificateAndKeys', function () { const certificateId = 'cert1' - const input: Iot.CreateKeysAndCertificateRequest = { setAsActive: undefined } - const expectedResponse: Iot.CreateKeysAndCertificateResponse = { + const input: CreateKeysAndCertificateRequest = { setAsActive: undefined } + const expectedResponse: CreateKeysAndCertificateResponse = { certificateId, certificateArn: 'arn', certificatePem: 'pem', @@ -91,7 +139,7 @@ describe('DefaultIotClient', function () { } it('creates Certificate and Key Pair', async function () { - mockIot.createKeysAndCertificate.returns(success(expectedResponse)) + mockIot.on(CreateKeysAndCertificateCommand).resolves(expectedResponse) const response = await createClient().createCertificateAndKeys(input) @@ -99,36 +147,37 @@ describe('DefaultIotClient', function () { }) it('throws an Error on failure', async function () { - mockIot.createKeysAndCertificate.returns(failure()) + mockIot.on(CreateKeysAndCertificateCommand).rejects(error) await assert.rejects(createClient().createCertificateAndKeys(input), error) }) }) describe('getEndpoint', function () { - const input: Iot.DescribeEndpointRequest = { endpointType: 'iot:Data-ATS' } + const input: DescribeEndpointRequest = { endpointType: 'iot:Data-ATS' } const endpointAddress = 'address' - const describeResponse: Iot.DescribeEndpointResponse = { endpointAddress } + const describeResponse: DescribeEndpointResponse = { endpointAddress } it('gets endpoint', async function () { - mockIot.describeEndpoint.returns(success(describeResponse)) + mockIot.on(DescribeEndpointCommand).resolves(describeResponse) const response = await createClient().getEndpoint() - mockIot.describeEndpoint.calledOnceWithExactly(sinon.match(input)) + assert.strictEqual(mockIot.commandCalls(DescribeEndpointCommand).length, 1) + assert.deepStrictEqual(mockIot.commandCalls(DescribeEndpointCommand)[0].args[0].input, input) assert.deepStrictEqual(response, endpointAddress) }) it('throws an Error on failure', async function () { - mockIot.describeEndpoint.returns(failure()) + mockIot.on(DescribeEndpointCommand).rejects(error) await assert.rejects(createClient().getEndpoint(), error) }) }) describe('getPolicyVersion', function () { - const input: Iot.GetPolicyVersionRequest = { policyName, policyVersionId: '1' } - const expectedResponse: Iot.GetPolicyVersionResponse = { + const input: GetPolicyVersionRequest = { policyName, policyVersionId: '1' } + const expectedResponse: GetPolicyVersionResponse = { policyName, policyDocument, policyArn: 'arn1', @@ -136,7 +185,7 @@ describe('DefaultIotClient', function () { } it('gets policy document for version', async function () { - mockIot.getPolicyVersion.returns(success(expectedResponse)) + mockIot.on(GetPolicyVersionCommand).resolves(expectedResponse) const response = await createClient().getPolicyVersion(input) @@ -144,7 +193,7 @@ describe('DefaultIotClient', function () { }) it('throws an Error on failure', async function () { - mockIot.getPolicyVersion.returns(failure()) + mockIot.on(GetPolicyVersionCommand).rejects(error) await assert.rejects(createClient().getPolicyVersion(input), error) }) @@ -153,18 +202,19 @@ describe('DefaultIotClient', function () { /* Functions that return void .*/ describe('deleteThing', function () { - const input: Iot.DeleteThingRequest = { thingName } + const input: DeleteThingRequest = { thingName } it('deletes a thing', async function () { - mockIot.deleteThing.returns(success({} as Iot.DeleteThingResponse)) + mockIot.on(DeleteThingCommand).resolves({} as DeleteThingResponse) await createClient().deleteThing({ thingName }) - assert(mockIot.deleteThing.calledOnceWithExactly(sinon.match(input))) + assert.strictEqual(mockIot.commandCalls(DeleteThingCommand).length, 1) + assert.deepStrictEqual(mockIot.commandCalls(DeleteThingCommand)[0].args[0].input, input) }) it('throws an Error on failure', async function () { - mockIot.deleteThing.returns(failure()) + mockIot.on(DeleteThingCommand).rejects(error) await assert.rejects(createClient().deleteThing({ thingName }), error) }) @@ -172,18 +222,19 @@ describe('DefaultIotClient', function () { describe('deleteCertificate', function () { const certificateId = 'cert1' - const input: Iot.DeleteCertificateRequest = { certificateId, forceDelete: undefined } + const input: DeleteCertificateRequest = { certificateId, forceDelete: undefined } it('deletes a certificate', async function () { - mockIot.deleteCertificate.returns(success()) + mockIot.on(DeleteCertificateCommand).resolves({}) await createClient().deleteCertificate(input) - assert(mockIot.deleteCertificate.calledOnceWithExactly(sinon.match(input))) + assert.strictEqual(mockIot.commandCalls(DeleteCertificateCommand).length, 1) + assert.deepStrictEqual(mockIot.commandCalls(DeleteCertificateCommand)[0].args[0].input, input) }) it('throws an Error on failure', async function () { - mockIot.deleteCertificate.returns(failure()) + mockIot.on(DeleteCertificateCommand).rejects(error) await assert.rejects(createClient().deleteCertificate(input), error) }) @@ -191,182 +242,192 @@ describe('DefaultIotClient', function () { describe('updateCertificate', function () { const certificateId = 'cert1' - const input: Iot.UpdateCertificateRequest = { certificateId, newStatus: 'ACTIVE' } + const input: UpdateCertificateRequest = { certificateId, newStatus: 'ACTIVE' } it('updates a certificate', async function () { - mockIot.updateCertificate.returns(success()) + mockIot.on(UpdateCertificateCommand).resolves({}) await createClient().updateCertificate(input) - assert(mockIot.updateCertificate.calledOnceWithExactly(sinon.match(input))) + assert.strictEqual(mockIot.commandCalls(UpdateCertificateCommand).length, 1) + assert.deepStrictEqual(mockIot.commandCalls(UpdateCertificateCommand)[0].args[0].input, input) }) it('throws an Error on failure', async function () { - mockIot.updateCertificate.returns(failure()) + mockIot.on(UpdateCertificateCommand).rejects(error) await assert.rejects(createClient().updateCertificate(input), error) }) }) describe('attachThingPrincipal', function () { - const input: Iot.AttachThingPrincipalRequest = { thingName, principal: 'arn1' } + const input: AttachThingPrincipalRequest = { thingName, principal: 'arn1' } it('attaches a certificate to a Thing', async function () { - mockIot.attachThingPrincipal.returns(success()) + mockIot.on(AttachThingPrincipalCommand).resolves({}) await createClient().attachThingPrincipal(input) - assert(mockIot.attachThingPrincipal.calledOnceWithExactly(sinon.match(input))) + assert.strictEqual(mockIot.commandCalls(AttachThingPrincipalCommand).length, 1) + assert.deepStrictEqual(mockIot.commandCalls(AttachThingPrincipalCommand)[0].args[0].input, input) }) it('throws an Error on failure', async function () { - mockIot.attachThingPrincipal.returns(failure()) + mockIot.on(AttachThingPrincipalCommand).rejects(error) await assert.rejects(createClient().attachThingPrincipal(input), error) }) }) describe('detachThingPrincipal', function () { - const input: Iot.DetachThingPrincipalRequest = { thingName, principal: 'arn1' } + const input: DetachThingPrincipalRequest = { thingName, principal: 'arn1' } it('detaches a certificate from a Thing', async function () { - mockIot.detachThingPrincipal.returns(success()) + mockIot.on(DetachThingPrincipalCommand).resolves({}) await createClient().detachThingPrincipal(input) - assert(mockIot.detachThingPrincipal.calledOnceWithExactly(sinon.match(input))) + assert.strictEqual(mockIot.commandCalls(DetachThingPrincipalCommand).length, 1) + assert.deepStrictEqual(mockIot.commandCalls(DetachThingPrincipalCommand)[0].args[0].input, input) }) it('throws an Error on failure', async function () { - mockIot.detachThingPrincipal.returns(failure()) + mockIot.on(DetachThingPrincipalCommand).rejects(error) await assert.rejects(createClient().detachThingPrincipal(input), error) }) }) describe('attachPolicy', function () { - const input: Iot.AttachPolicyRequest = { policyName, target: 'arn1' } + const input: AttachPolicyRequest = { policyName, target: 'arn1' } it('attaches a policy to a certificate', async function () { - mockIot.attachPolicy.returns(success()) + mockIot.on(AttachPolicyCommand).resolves({}) await createClient().attachPolicy(input) - assert(mockIot.attachPolicy.calledOnceWithExactly(sinon.match(input))) + assert.strictEqual(mockIot.commandCalls(AttachPolicyCommand).length, 1) + assert.deepStrictEqual(mockIot.commandCalls(AttachPolicyCommand)[0].args[0].input, input) }) it('throws an Error on failure', async function () { - mockIot.attachPolicy.returns(failure()) + mockIot.on(AttachPolicyCommand).rejects(error) await assert.rejects(createClient().attachPolicy(input), error) }) }) describe('detachPolicy', function () { - const input: Iot.DetachPolicyRequest = { policyName, target: 'arn1' } + const input: DetachPolicyRequest = { policyName, target: 'arn1' } it('detaches a policy from a certificate', async function () { - mockIot.detachPolicy.returns(success()) + mockIot.on(DetachPolicyCommand).resolves({}) await createClient().detachPolicy(input) - assert(mockIot.detachPolicy.calledOnceWithExactly(sinon.match(input))) + assert.strictEqual(mockIot.commandCalls(DetachPolicyCommand).length, 1) + assert.deepStrictEqual(mockIot.commandCalls(DetachPolicyCommand)[0].args[0].input, input) }) it('throws an Error on failure', async function () { - mockIot.detachPolicy.returns(failure()) + mockIot.on(DetachPolicyCommand).rejects(error) await assert.rejects(createClient().detachPolicy(input), error) }) }) describe('createPolicy', function () { - const input: Iot.CreatePolicyRequest = { policyName, policyDocument } - const expectedResponse: Iot.CreatePolicyResponse = { policyName, policyDocument, policyArn: 'arn1' } + const input: CreatePolicyRequest = { policyName, policyDocument } + const expectedResponse: CreatePolicyResponse = { policyName, policyDocument, policyArn: 'arn1' } it('creates a policy from a document', async function () { - mockIot.createPolicy.returns(success(expectedResponse)) + mockIot.on(CreatePolicyCommand).resolves(expectedResponse) await createClient().createPolicy(input) - assert(mockIot.createPolicy.calledOnceWithExactly(sinon.match(input))) + assert.strictEqual(mockIot.commandCalls(CreatePolicyCommand).length, 1) + assert.deepStrictEqual(mockIot.commandCalls(CreatePolicyCommand)[0].args[0].input, input) }) it('throws an Error on failure', async function () { - mockIot.createPolicy.returns(failure()) + mockIot.on(CreatePolicyCommand).rejects(error) await assert.rejects(createClient().createPolicy(input), error) }) }) describe('deletePolicy', function () { - const input: Iot.DeletePolicyRequest = { policyName } + const input: DeletePolicyRequest = { policyName } it('deletes a policy', async function () { - mockIot.deletePolicy.returns(success()) + mockIot.on(DeletePolicyCommand).resolves({}) await createClient().deletePolicy(input) - assert(mockIot.deletePolicy.calledOnceWithExactly(sinon.match(input))) + assert.strictEqual(mockIot.commandCalls(DeletePolicyCommand).length, 1) + assert.deepStrictEqual(mockIot.commandCalls(DeletePolicyCommand)[0].args[0].input, input) }) it('throws an Error on failure', async function () { - mockIot.deletePolicy.returns(failure()) + mockIot.on(DeletePolicyCommand).rejects(error) await assert.rejects(createClient().deletePolicy(input), error) }) }) describe('createPolicyVersion', function () { - const input: Iot.CreatePolicyVersionRequest = { policyName, policyDocument } - const expectedResponse: Iot.CreatePolicyVersionResponse = { policyDocument, policyArn: 'arn1' } + const input: CreatePolicyVersionRequest = { policyName, policyDocument } + const expectedResponse: CreatePolicyVersionResponse = { policyDocument, policyArn: 'arn1' } it('creates a policy version from a document', async function () { - mockIot.createPolicyVersion.returns(success(expectedResponse)) + mockIot.on(CreatePolicyVersionCommand).resolves(expectedResponse) await createClient().createPolicyVersion(input) - assert(mockIot.createPolicyVersion.calledOnceWithExactly(sinon.match(input))) + assert.strictEqual(mockIot.commandCalls(CreatePolicyVersionCommand).length, 1) + assert.deepStrictEqual(mockIot.commandCalls(CreatePolicyVersionCommand)[0].args[0].input, input) }) it('throws an Error on failure', async function () { - mockIot.createPolicyVersion.returns(failure()) + mockIot.on(CreatePolicyVersionCommand).rejects(error) await assert.rejects(createClient().createPolicyVersion(input), error) }) }) describe('deletePolicyVersion', function () { - const input: Iot.DeletePolicyVersionRequest = { policyName, policyVersionId: '1' } + const input: DeletePolicyVersionRequest = { policyName, policyVersionId: '1' } it('deletes a policy version', async function () { - mockIot.deletePolicyVersion.returns(success()) + mockIot.on(DeletePolicyVersionCommand).resolves({}) await createClient().deletePolicyVersion(input) - assert(mockIot.deletePolicyVersion.calledOnceWithExactly(sinon.match(input))) + assert.strictEqual(mockIot.commandCalls(DeletePolicyVersionCommand).length, 1) + assert.deepStrictEqual(mockIot.commandCalls(DeletePolicyVersionCommand)[0].args[0].input, input) }) it('throws an Error on failure', async function () { - mockIot.deletePolicyVersion.returns(failure()) + mockIot.on(DeletePolicyVersionCommand).rejects(error) await assert.rejects(createClient().deletePolicyVersion(input), error) }) }) describe('setDefaultPolicyVersion', function () { - const input: Iot.SetDefaultPolicyVersionRequest = { policyName, policyVersionId: '1' } + const input: SetDefaultPolicyVersionRequest = { policyName, policyVersionId: '1' } it('deletes a policy version', async function () { - mockIot.setDefaultPolicyVersion.returns(success()) + mockIot.on(SetDefaultPolicyVersionCommand).resolves({}) await createClient().setDefaultPolicyVersion(input) - assert(mockIot.setDefaultPolicyVersion.calledOnceWithExactly(sinon.match(input))) + assert.strictEqual(mockIot.commandCalls(SetDefaultPolicyVersionCommand).length, 1) + assert.deepStrictEqual(mockIot.commandCalls(SetDefaultPolicyVersionCommand)[0].args[0].input, input) }) it('throws an Error on failure', async function () { - mockIot.setDefaultPolicyVersion.returns(failure()) + mockIot.on(SetDefaultPolicyVersionCommand).rejects(error) await assert.rejects(createClient().setDefaultPolicyVersion(input), error) }) @@ -375,11 +436,11 @@ describe('DefaultIotClient', function () { // /* Functions that list resources. describe('listThings', function () { - const input: Iot.ListThingsRequest = { maxResults, nextToken } - const expectedResponse: Iot.ListThingsResponse = { things: [{ thingName: 'thing1' }], nextToken } + const input: ListThingsRequest = { maxResults, nextToken } + const expectedResponse: ListThingsResponse = { things: [{ thingName: 'thing1' }], nextToken } it('lists things', async function () { - mockIot.listThings.returns(success(expectedResponse)) + mockIot.on(ListThingsCommand).resolves(expectedResponse) const response = await createClient().listThings(input) @@ -387,21 +448,21 @@ describe('DefaultIotClient', function () { }) it('throws an Error on failure', async function () { - mockIot.listThings.returns(failure()) + mockIot.on(ListThingsCommand).rejects(error) await assert.rejects(createClient().listThings(input), error) }) }) describe('listCertificates', function () { - const input: Iot.ListCertificatesRequest = { pageSize, marker, ascendingOrder: undefined } - const expectedResponse: Iot.ListCertificatesResponse = { + const input: ListCertificatesRequest = { pageSize, marker, ascendingOrder: undefined } + const expectedResponse: ListCertificatesResponse = { certificates: [{ certificateId: 'cert1' }], nextMarker: marker, } it('lists certificates', async function () { - mockIot.listCertificates.returns(success(expectedResponse)) + mockIot.on(ListCertificatesCommand).resolves(expectedResponse) const response = await createClient().listCertificates(input) @@ -409,7 +470,7 @@ describe('DefaultIotClient', function () { }) it('throws an Error on failure', async function () { - mockIot.listCertificates.returns(failure()) + mockIot.on(ListCertificatesCommand).rejects(error) await assert.rejects(createClient().listCertificates(input), error) }) @@ -418,11 +479,11 @@ describe('DefaultIotClient', function () { describe('listThingCertificates', function () { const certificateId = 'cert1' const certArn = 'arn:aws:iot:us-west-2:0123456789:cert/cert1' - const input: Iot.ListThingPrincipalsRequest = { thingName, maxResults, nextToken } - const principalsResponse: Iot.ListThingPrincipalsResponse = { principals: [certArn], nextToken } + const input: ListThingPrincipalsRequest = { thingName, maxResults, nextToken } + const principalsResponse: ListThingPrincipalsResponse = { principals: [certArn], nextToken } - const describeInput: Iot.DescribeCertificateRequest = { certificateId } - const describeResponse: Iot.DescribeCertificateResponse = { + const describeInput: DescribeCertificateRequest = { certificateId } + const describeResponse: DescribeCertificateResponse = { certificateDescription: { certificateId, certificateArn: certArn }, } @@ -432,36 +493,37 @@ describe('DefaultIotClient', function () { } it('lists certificates', async function () { - mockIot.listThingPrincipals.returns(success(principalsResponse)) - mockIot.describeCertificate.returns(success(describeResponse)) + mockIot.on(ListThingPrincipalsCommand).resolves(principalsResponse) + mockIot.on(DescribeCertificateCommand).resolves(describeResponse) const response = await createClient().listThingCertificates(input) - mockIot.describeCertificate.calledOnceWithExactly(sinon.match(describeInput)) + assert.strictEqual(mockIot.commandCalls(DescribeCertificateCommand).length, 1) + assert.deepStrictEqual(mockIot.commandCalls(DescribeCertificateCommand)[0].args[0].input, describeInput) assert.deepStrictEqual(response, expectedResponse) }) it('throws an Error when certificate listing fails', async function () { - mockIot.listThingPrincipals.returns(failure()) + mockIot.on(ListThingPrincipalsCommand).rejects(error) await assert.rejects(createClient().listThingCertificates(input), error) }) it('throws an Error when certificate description fails', async function () { - mockIot.listThingPrincipals.returns(success(principalsResponse)) - mockIot.describeCertificate.returns(failure()) + mockIot.on(ListThingPrincipalsCommand).resolves(principalsResponse) + mockIot.on(DescribeCertificateCommand).rejects(error) await assert.rejects(createClient().listThingCertificates(input), error) }) }) describe('listThingsForCert', function () { - const input: Iot.ListPrincipalThingsRequest = { principal: 'arn1', maxResults, nextToken } - const listResponse: Iot.ListPrincipalThingsResponse = { things: [thingName], nextToken } + const input: ListPrincipalThingsRequest = { principal: 'arn1', maxResults, nextToken } + const listResponse: ListPrincipalThingsResponse = { things: [thingName], nextToken } const expectedResponse = [thingName] it('lists things', async function () { - mockIot.listPrincipalThings.returns(success(listResponse)) + mockIot.on(ListPrincipalThingsCommand).resolves(listResponse) const response = await createClient().listThingsForCert(input) @@ -469,18 +531,18 @@ describe('DefaultIotClient', function () { }) it('throws an Error on failure', async function () { - mockIot.listPrincipalThings.returns(failure()) + mockIot.on(ListPrincipalThingsCommand).rejects(error) await assert.rejects(createClient().listThingsForCert(input), error) }) }) describe('listPolicies', function () { - const input: Iot.ListPoliciesRequest = { pageSize, marker, ascendingOrder: undefined } - const expectedResponse: Iot.ListPoliciesResponse = { policies: [{ policyName }], nextMarker: marker } + const input: ListPoliciesRequest = { pageSize, marker, ascendingOrder: undefined } + const expectedResponse: ListPoliciesResponse = { policies: [{ policyName }], nextMarker: marker } it('lists policies', async function () { - mockIot.listPolicies.returns(success(expectedResponse)) + mockIot.on(ListPoliciesCommand).resolves(expectedResponse) const response = await createClient().listPolicies(input) @@ -488,23 +550,23 @@ describe('DefaultIotClient', function () { }) it('throws an Error on failure', async function () { - mockIot.listPolicies.returns(failure()) + mockIot.on(ListPoliciesCommand).rejects(error) await assert.rejects(createClient().listPolicies(input), error) }) }) describe('listPrincipalPolicies', function () { - const input: Iot.ListPrincipalPoliciesRequest = { + const input: ListPrincipalPoliciesRequest = { pageSize, marker, ascendingOrder: undefined, principal: 'arn1', } - const expectedResponse: Iot.ListPoliciesResponse = { policies: [{ policyName }], nextMarker: marker } + const expectedResponse: ListPoliciesResponse = { policies: [{ policyName }], nextMarker: marker } it('lists policies for certificate', async function () { - mockIot.listPrincipalPolicies.returns(success(expectedResponse)) + mockIot.on(ListPrincipalPoliciesCommand).resolves(expectedResponse) const response = await createClient().listPrincipalPolicies(input) @@ -512,7 +574,7 @@ describe('DefaultIotClient', function () { }) it('throws an Error on failure', async function () { - mockIot.listPrincipalPolicies.returns(failure()) + mockIot.on(ListPrincipalPoliciesCommand).rejects(error) await assert.rejects(createClient().listPrincipalPolicies(input), error) }) @@ -520,11 +582,11 @@ describe('DefaultIotClient', function () { describe('listPolicyTargets', function () { const targets = ['arn1', 'arn2'] - const input: Iot.ListTargetsForPolicyRequest = { policyName, pageSize, marker } - const listResponse: Iot.ListTargetsForPolicyResponse = { targets, nextMarker: marker } + const input: ListTargetsForPolicyRequest = { policyName, pageSize, marker } + const listResponse: ListTargetsForPolicyResponse = { targets, nextMarker: marker } it('lists certificates', async function () { - mockIot.listTargetsForPolicy.returns(success(listResponse)) + mockIot.on(ListTargetsForPolicyCommand).resolves(listResponse) const response = await createClient().listPolicyTargets(input) @@ -532,20 +594,20 @@ describe('DefaultIotClient', function () { }) it('throws an Error on failure', async function () { - mockIot.listTargetsForPolicy.returns(failure()) + mockIot.on(ListTargetsForPolicyCommand).rejects(error) await assert.rejects(createClient().listPolicyTargets(input), error) }) }) describe('listPolicyVersions', function () { - const input: Iot.ListPolicyVersionsRequest = { policyName } - const expectedVersion1: Iot.PolicyVersion = { versionId: '1' } - const expectedVersion2: Iot.PolicyVersion = { versionId: '2' } - const listResponse: Iot.ListPolicyVersionsResponse = { policyVersions: [expectedVersion1, expectedVersion2] } + const input: ListPolicyVersionsRequest = { policyName } + const expectedVersion1: PolicyVersion = { versionId: '1' } + const expectedVersion2: PolicyVersion = { versionId: '2' } + const listResponse: ListPolicyVersionsResponse = { policyVersions: [expectedVersion1, expectedVersion2] } it('lists policy versions', async function () { - mockIot.listPolicyVersions.returns(success(listResponse)) + mockIot.on(ListPolicyVersionsCommand).resolves(listResponse) const iterable = createClient().listPolicyVersions(input) const responses = [] @@ -561,7 +623,7 @@ describe('DefaultIotClient', function () { }) it('throws an Error on iterate failure', async function () { - mockIot.listPolicyVersions.returns(failure()) + mockIot.on(ListPolicyVersionsCommand).rejects(error) const iterable = createClient().listPolicyVersions(input) await assert.rejects(iterable.next(), error)