From 821d11427c5c876c8a06e6c599cd43a173dfc1bf Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 12 Oct 2023 08:29:51 -0700 Subject: [PATCH 01/19] test: credentials.env --- src/transforms/v2-to-v3/__fixtures__/credentials/env.input.js | 3 +++ src/transforms/v2-to-v3/__fixtures__/credentials/env.output.js | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/env.input.js create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/env.output.js diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/env.input.js b/src/transforms/v2-to-v3/__fixtures__/credentials/env.input.js new file mode 100644 index 000000000..ed0dda65a --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/env.input.js @@ -0,0 +1,3 @@ +import AWS from "aws-sdk"; + +const credentials = new AWS.EnvironmentCredentials("AWS"); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/env.output.js b/src/transforms/v2-to-v3/__fixtures__/credentials/env.output.js new file mode 100644 index 000000000..0631bdda6 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/env.output.js @@ -0,0 +1,3 @@ +import { fromEnv } from "@aws-sdk/credential-providers"; + +const credentials = fromEnv("AWS"); \ No newline at end of file From 975b7fdf5aad3100584b345f70c41cb0cf1ec6e2 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 12 Oct 2023 08:46:28 -0700 Subject: [PATCH 02/19] feat: add transform for AWS.EnvironmentCredentials --- .../getAwsCredentialsNewExpression.ts | 23 +++++++++++++++++++ .../v2-to-v3/aws-credentials/index.ts | 1 + .../aws-credentials/replaceAwsCredentials.ts | 12 ++++++++++ .../aws-credentials/replaceEnvCredentials.ts | 14 +++++++++++ src/transforms/v2-to-v3/transformer.ts | 2 ++ 5 files changed, 52 insertions(+) create mode 100644 src/transforms/v2-to-v3/aws-credentials/getAwsCredentialsNewExpression.ts create mode 100644 src/transforms/v2-to-v3/aws-credentials/index.ts create mode 100644 src/transforms/v2-to-v3/aws-credentials/replaceAwsCredentials.ts create mode 100644 src/transforms/v2-to-v3/aws-credentials/replaceEnvCredentials.ts diff --git a/src/transforms/v2-to-v3/aws-credentials/getAwsCredentialsNewExpression.ts b/src/transforms/v2-to-v3/aws-credentials/getAwsCredentialsNewExpression.ts new file mode 100644 index 000000000..6090064ee --- /dev/null +++ b/src/transforms/v2-to-v3/aws-credentials/getAwsCredentialsNewExpression.ts @@ -0,0 +1,23 @@ +import { Collection, JSCodeshift } from "jscodeshift"; + +export interface GetAwsCredentialsNewExpressionOptions { + v2GlobalName: string; + functionName: string; +} + +export const getAwsCredentialsNewExpression = ( + j: JSCodeshift, + source: Collection, + { v2GlobalName, functionName }: GetAwsCredentialsNewExpressionOptions +) => + source.find(j.NewExpression, { + type: "NewExpression", + callee: { + type: "MemberExpression", + object: { + type: "Identifier", + name: v2GlobalName, + }, + property: { name: functionName }, + }, + }); diff --git a/src/transforms/v2-to-v3/aws-credentials/index.ts b/src/transforms/v2-to-v3/aws-credentials/index.ts new file mode 100644 index 000000000..9b0dcb840 --- /dev/null +++ b/src/transforms/v2-to-v3/aws-credentials/index.ts @@ -0,0 +1 @@ +export * from "./replaceAwsCredentials"; diff --git a/src/transforms/v2-to-v3/aws-credentials/replaceAwsCredentials.ts b/src/transforms/v2-to-v3/aws-credentials/replaceAwsCredentials.ts new file mode 100644 index 000000000..90bbd1812 --- /dev/null +++ b/src/transforms/v2-to-v3/aws-credentials/replaceAwsCredentials.ts @@ -0,0 +1,12 @@ +import { Collection, JSCodeshift } from "jscodeshift"; +import { replaceEnvCredentials } from "./replaceEnvCredentials"; + +export const replaceAwsCredentials = ( + j: JSCodeshift, + source: Collection, + v2GlobalName?: string +) => { + if (!v2GlobalName) return; + + replaceEnvCredentials(j, source, v2GlobalName); +}; diff --git a/src/transforms/v2-to-v3/aws-credentials/replaceEnvCredentials.ts b/src/transforms/v2-to-v3/aws-credentials/replaceEnvCredentials.ts new file mode 100644 index 000000000..15663a2cb --- /dev/null +++ b/src/transforms/v2-to-v3/aws-credentials/replaceEnvCredentials.ts @@ -0,0 +1,14 @@ +import { Collection, JSCodeshift } from "jscodeshift"; + +import { getAwsCredentialsNewExpression } from "./getAwsCredentialsNewExpression"; + +export const replaceEnvCredentials = ( + j: JSCodeshift, + source: Collection, + v2GlobalName: string +) => { + const functionName = "EnvironmentCredentials"; + getAwsCredentialsNewExpression(j, source, { v2GlobalName, functionName }).replaceWith( + ({ node }) => j.callExpression(j.identifier("fromEnv"), node.arguments) + ); +}; diff --git a/src/transforms/v2-to-v3/transformer.ts b/src/transforms/v2-to-v3/transformer.ts index 52e6ce635..2a1e38bff 100644 --- a/src/transforms/v2-to-v3/transformer.ts +++ b/src/transforms/v2-to-v3/transformer.ts @@ -9,6 +9,7 @@ import { replaceS3GetSignedUrlApi, getClientIdentifiersRecord, } from "./apis"; +import { replaceAwsCredentials } from "./aws-credentials"; import { replaceAwsUtilFunctions } from "./aws-util"; import { replaceClientCreation, replaceDocClientCreation } from "./client-instances"; import { @@ -91,6 +92,7 @@ const transformer = async (file: FileInfo, api: API) => { replaceClientCreation(j, source, { ...v2Options, v3ClientName }); replaceDocClientCreation(j, source, v2Options); } + replaceAwsCredentials(j, source, v2GlobalName); replaceAwsUtilFunctions(j, source, v2GlobalName); removeGlobalModule(j, source, { v2GlobalName, importType }); From 069c3153f4ddc3b17febef4febb1ddd6a2717352 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 12 Oct 2023 14:37:18 -0700 Subject: [PATCH 03/19] Remove replaceEnvCredentials --- .../aws-credentials/replaceAwsCredentials.ts | 7 +++++-- .../aws-credentials/replaceEnvCredentials.ts | 14 -------------- 2 files changed, 5 insertions(+), 16 deletions(-) delete mode 100644 src/transforms/v2-to-v3/aws-credentials/replaceEnvCredentials.ts diff --git a/src/transforms/v2-to-v3/aws-credentials/replaceAwsCredentials.ts b/src/transforms/v2-to-v3/aws-credentials/replaceAwsCredentials.ts index 90bbd1812..b30c0b3dc 100644 --- a/src/transforms/v2-to-v3/aws-credentials/replaceAwsCredentials.ts +++ b/src/transforms/v2-to-v3/aws-credentials/replaceAwsCredentials.ts @@ -1,5 +1,5 @@ import { Collection, JSCodeshift } from "jscodeshift"; -import { replaceEnvCredentials } from "./replaceEnvCredentials"; +import { getAwsCredentialsNewExpression } from "./getAwsCredentialsNewExpression"; export const replaceAwsCredentials = ( j: JSCodeshift, @@ -8,5 +8,8 @@ export const replaceAwsCredentials = ( ) => { if (!v2GlobalName) return; - replaceEnvCredentials(j, source, v2GlobalName); + const functionName = "EnvironmentCredentials"; + getAwsCredentialsNewExpression(j, source, { v2GlobalName, functionName }).replaceWith( + ({ node }) => j.callExpression(j.identifier("fromEnv"), node.arguments) + ); }; diff --git a/src/transforms/v2-to-v3/aws-credentials/replaceEnvCredentials.ts b/src/transforms/v2-to-v3/aws-credentials/replaceEnvCredentials.ts deleted file mode 100644 index 15663a2cb..000000000 --- a/src/transforms/v2-to-v3/aws-credentials/replaceEnvCredentials.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Collection, JSCodeshift } from "jscodeshift"; - -import { getAwsCredentialsNewExpression } from "./getAwsCredentialsNewExpression"; - -export const replaceEnvCredentials = ( - j: JSCodeshift, - source: Collection, - v2GlobalName: string -) => { - const functionName = "EnvironmentCredentials"; - getAwsCredentialsNewExpression(j, source, { v2GlobalName, functionName }).replaceWith( - ({ node }) => j.callExpression(j.identifier("fromEnv"), node.arguments) - ); -}; From 5f7f45207633d259d73060fe07d6c1fd1c53c0f0 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 12 Oct 2023 14:38:58 -0700 Subject: [PATCH 04/19] Move replaceAwsCredentials to apis folder --- .../{aws-credentials => apis}/getAwsCredentialsNewExpression.ts | 0 src/transforms/v2-to-v3/apis/index.ts | 1 + .../v2-to-v3/{aws-credentials => apis}/replaceAwsCredentials.ts | 0 src/transforms/v2-to-v3/aws-credentials/index.ts | 1 - src/transforms/v2-to-v3/transformer.ts | 2 +- 5 files changed, 2 insertions(+), 2 deletions(-) rename src/transforms/v2-to-v3/{aws-credentials => apis}/getAwsCredentialsNewExpression.ts (100%) rename src/transforms/v2-to-v3/{aws-credentials => apis}/replaceAwsCredentials.ts (100%) delete mode 100644 src/transforms/v2-to-v3/aws-credentials/index.ts diff --git a/src/transforms/v2-to-v3/aws-credentials/getAwsCredentialsNewExpression.ts b/src/transforms/v2-to-v3/apis/getAwsCredentialsNewExpression.ts similarity index 100% rename from src/transforms/v2-to-v3/aws-credentials/getAwsCredentialsNewExpression.ts rename to src/transforms/v2-to-v3/apis/getAwsCredentialsNewExpression.ts diff --git a/src/transforms/v2-to-v3/apis/index.ts b/src/transforms/v2-to-v3/apis/index.ts index f2eb18885..dbce9211d 100644 --- a/src/transforms/v2-to-v3/apis/index.ts +++ b/src/transforms/v2-to-v3/apis/index.ts @@ -6,6 +6,7 @@ export * from "./getS3SignedUrlApiNames"; export * from "./isS3GetSignedUrlApiUsed"; export * from "./isS3UploadApiUsed"; export * from "./removePromiseCalls"; +export * from "./replaceAwsCredentials"; export * from "./replaceS3GetSignedUrlApi"; export * from "./replaceS3UploadApi"; export * from "./replaceWaiterApi"; diff --git a/src/transforms/v2-to-v3/aws-credentials/replaceAwsCredentials.ts b/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts similarity index 100% rename from src/transforms/v2-to-v3/aws-credentials/replaceAwsCredentials.ts rename to src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts diff --git a/src/transforms/v2-to-v3/aws-credentials/index.ts b/src/transforms/v2-to-v3/aws-credentials/index.ts deleted file mode 100644 index 9b0dcb840..000000000 --- a/src/transforms/v2-to-v3/aws-credentials/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./replaceAwsCredentials"; diff --git a/src/transforms/v2-to-v3/transformer.ts b/src/transforms/v2-to-v3/transformer.ts index 2a1e38bff..02f2dacfd 100644 --- a/src/transforms/v2-to-v3/transformer.ts +++ b/src/transforms/v2-to-v3/transformer.ts @@ -8,8 +8,8 @@ import { replaceS3UploadApi, replaceS3GetSignedUrlApi, getClientIdentifiersRecord, + replaceAwsCredentials, } from "./apis"; -import { replaceAwsCredentials } from "./aws-credentials"; import { replaceAwsUtilFunctions } from "./aws-util"; import { replaceClientCreation, replaceDocClientCreation } from "./client-instances"; import { From c46e983278ffe600040475ecc3a385fe3e1c24ff Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 12 Oct 2023 14:45:11 -0700 Subject: [PATCH 05/19] Add AWS_CREDENTIALS_MAP --- src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts | 6 ++++++ src/transforms/v2-to-v3/config/index.ts | 1 + 2 files changed, 7 insertions(+) create mode 100644 src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts diff --git a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts new file mode 100644 index 000000000..e2d4f810c --- /dev/null +++ b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts @@ -0,0 +1,6 @@ +/** + * Maps the AWS credentials class name in v2 to the v3 equivalent provider. + */ +export const AWS_CREDENTIALS_MAP: Record = { + EnvironmentCredentials: "fromEnv", +}; diff --git a/src/transforms/v2-to-v3/config/index.ts b/src/transforms/v2-to-v3/config/index.ts index c71b336a9..a70ca244b 100644 --- a/src/transforms/v2-to-v3/config/index.ts +++ b/src/transforms/v2-to-v3/config/index.ts @@ -1,3 +1,4 @@ +export * from "./AWS_CREDENTIALS_MAP"; export * from "./CLIENT_NAMES"; export * from "./CLIENT_NAMES_MAP"; export * from "./CLIENT_PACKAGE_NAMES_MAP"; From 93ab5dc4c2ecef1544da7c2cf98eca85ec87859d Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 12 Oct 2023 14:46:04 -0700 Subject: [PATCH 06/19] Transform over Object.entries(AWS_CREDENTIALS_MAP) --- .../v2-to-v3/apis/getAwsCredentialsNewExpression.ts | 6 +++--- src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/transforms/v2-to-v3/apis/getAwsCredentialsNewExpression.ts b/src/transforms/v2-to-v3/apis/getAwsCredentialsNewExpression.ts index 6090064ee..f46f4c179 100644 --- a/src/transforms/v2-to-v3/apis/getAwsCredentialsNewExpression.ts +++ b/src/transforms/v2-to-v3/apis/getAwsCredentialsNewExpression.ts @@ -2,13 +2,13 @@ import { Collection, JSCodeshift } from "jscodeshift"; export interface GetAwsCredentialsNewExpressionOptions { v2GlobalName: string; - functionName: string; + className: string; } export const getAwsCredentialsNewExpression = ( j: JSCodeshift, source: Collection, - { v2GlobalName, functionName }: GetAwsCredentialsNewExpressionOptions + { v2GlobalName, className }: GetAwsCredentialsNewExpressionOptions ) => source.find(j.NewExpression, { type: "NewExpression", @@ -18,6 +18,6 @@ export const getAwsCredentialsNewExpression = ( type: "Identifier", name: v2GlobalName, }, - property: { name: functionName }, + property: { name: className }, }, }); diff --git a/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts b/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts index b30c0b3dc..79429cd4e 100644 --- a/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts +++ b/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts @@ -1,4 +1,5 @@ import { Collection, JSCodeshift } from "jscodeshift"; +import { AWS_CREDENTIALS_MAP } from "../config"; import { getAwsCredentialsNewExpression } from "./getAwsCredentialsNewExpression"; export const replaceAwsCredentials = ( @@ -8,8 +9,10 @@ export const replaceAwsCredentials = ( ) => { if (!v2GlobalName) return; - const functionName = "EnvironmentCredentials"; - getAwsCredentialsNewExpression(j, source, { v2GlobalName, functionName }).replaceWith( - ({ node }) => j.callExpression(j.identifier("fromEnv"), node.arguments) - ); + for (const [v2CredentialsName, v3ProviderName] of Object.entries(AWS_CREDENTIALS_MAP)) { + getAwsCredentialsNewExpression(j, source, { + v2GlobalName, + className: v2CredentialsName, + }).replaceWith(({ node }) => j.callExpression(j.identifier(v3ProviderName), node.arguments)); + } }; From 547a4d78905008288f38dc7e5e24c22a4380a236 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:00:38 -0700 Subject: [PATCH 07/19] Set-up stage for adding package imports --- ...n.ts => getAwsCredentialsNewExpressions.ts} | 2 +- .../v2-to-v3/apis/replaceAwsCredentials.ts | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) rename src/transforms/v2-to-v3/apis/{getAwsCredentialsNewExpression.ts => getAwsCredentialsNewExpressions.ts} (91%) diff --git a/src/transforms/v2-to-v3/apis/getAwsCredentialsNewExpression.ts b/src/transforms/v2-to-v3/apis/getAwsCredentialsNewExpressions.ts similarity index 91% rename from src/transforms/v2-to-v3/apis/getAwsCredentialsNewExpression.ts rename to src/transforms/v2-to-v3/apis/getAwsCredentialsNewExpressions.ts index f46f4c179..fa5f24971 100644 --- a/src/transforms/v2-to-v3/apis/getAwsCredentialsNewExpression.ts +++ b/src/transforms/v2-to-v3/apis/getAwsCredentialsNewExpressions.ts @@ -5,7 +5,7 @@ export interface GetAwsCredentialsNewExpressionOptions { className: string; } -export const getAwsCredentialsNewExpression = ( +export const getAwsCredentialsNewExpressions = ( j: JSCodeshift, source: Collection, { v2GlobalName, className }: GetAwsCredentialsNewExpressionOptions diff --git a/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts b/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts index 79429cd4e..62bfeab82 100644 --- a/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts +++ b/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts @@ -1,6 +1,6 @@ import { Collection, JSCodeshift } from "jscodeshift"; import { AWS_CREDENTIALS_MAP } from "../config"; -import { getAwsCredentialsNewExpression } from "./getAwsCredentialsNewExpression"; +import { getAwsCredentialsNewExpressions } from "./getAwsCredentialsNewExpressions"; export const replaceAwsCredentials = ( j: JSCodeshift, @@ -10,9 +10,21 @@ export const replaceAwsCredentials = ( if (!v2GlobalName) return; for (const [v2CredentialsName, v3ProviderName] of Object.entries(AWS_CREDENTIALS_MAP)) { - getAwsCredentialsNewExpression(j, source, { + const credsNewExpressions = getAwsCredentialsNewExpressions(j, source, { v2GlobalName, className: v2CredentialsName, - }).replaceWith(({ node }) => j.callExpression(j.identifier(v3ProviderName), node.arguments)); + }); + const credsNewExpressionCount = credsNewExpressions.size(); + + if (credsNewExpressionCount > 0) { + // addClientNamedModule(j, source, { + // ...options, + // importedName: v3ProviderName, + // v3ClientPackageName: "@aws-sdk/credential-provider", + // }); + credsNewExpressions.replaceWith(({ node }) => + j.callExpression(j.identifier(v3ProviderName), node.arguments) + ); + } } }; From 56f6f4ff917b1fdc3f99903750f2b3c983bb2836 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 20 Oct 2023 07:37:46 -0700 Subject: [PATCH 08/19] chore: pass importType to replaceAwsCredentials --- .../v2-to-v3/apis/replaceAwsCredentials.ts | 12 +++++++++--- src/transforms/v2-to-v3/transformer.ts | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts b/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts index 62bfeab82..23ce6af2d 100644 --- a/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts +++ b/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts @@ -1,11 +1,17 @@ import { Collection, JSCodeshift } from "jscodeshift"; import { AWS_CREDENTIALS_MAP } from "../config"; +import { ImportType } from "../modules"; import { getAwsCredentialsNewExpressions } from "./getAwsCredentialsNewExpressions"; +export interface ReplaceAwsCredentialsOptions { + v2GlobalName?: string; + importType: ImportType; +} + export const replaceAwsCredentials = ( j: JSCodeshift, source: Collection, - v2GlobalName?: string + { v2GlobalName }: ReplaceAwsCredentialsOptions ) => { if (!v2GlobalName) return; @@ -17,8 +23,8 @@ export const replaceAwsCredentials = ( const credsNewExpressionCount = credsNewExpressions.size(); if (credsNewExpressionCount > 0) { - // addClientNamedModule(j, source, { - // ...options, + // ToDo: Call importType agnostic addNamedModule + // addNamedModule(j, source, { // importedName: v3ProviderName, // v3ClientPackageName: "@aws-sdk/credential-provider", // }); diff --git a/src/transforms/v2-to-v3/transformer.ts b/src/transforms/v2-to-v3/transformer.ts index 02f2dacfd..1e387b474 100644 --- a/src/transforms/v2-to-v3/transformer.ts +++ b/src/transforms/v2-to-v3/transformer.ts @@ -92,7 +92,7 @@ const transformer = async (file: FileInfo, api: API) => { replaceClientCreation(j, source, { ...v2Options, v3ClientName }); replaceDocClientCreation(j, source, v2Options); } - replaceAwsCredentials(j, source, v2GlobalName); + replaceAwsCredentials(j, source, { v2GlobalName, importType }); replaceAwsUtilFunctions(j, source, v2GlobalName); removeGlobalModule(j, source, { v2GlobalName, importType }); From ea7f92dfb97fd1e7ab5c8f1878152b0c6a9b9d39 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:11:28 -0700 Subject: [PATCH 09/19] Add import for credential provider --- .../v2-to-v3/apis/replaceAwsCredentials.ts | 14 +++++++------- src/transforms/v2-to-v3/modules/index.ts | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts b/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts index 23ce6af2d..05a2f47de 100644 --- a/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts +++ b/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts @@ -1,6 +1,6 @@ import { Collection, JSCodeshift } from "jscodeshift"; import { AWS_CREDENTIALS_MAP } from "../config"; -import { ImportType } from "../modules"; +import { ImportType, addNamedModule } from "../modules"; import { getAwsCredentialsNewExpressions } from "./getAwsCredentialsNewExpressions"; export interface ReplaceAwsCredentialsOptions { @@ -11,7 +11,7 @@ export interface ReplaceAwsCredentialsOptions { export const replaceAwsCredentials = ( j: JSCodeshift, source: Collection, - { v2GlobalName }: ReplaceAwsCredentialsOptions + { v2GlobalName, importType }: ReplaceAwsCredentialsOptions ) => { if (!v2GlobalName) return; @@ -23,11 +23,11 @@ export const replaceAwsCredentials = ( const credsNewExpressionCount = credsNewExpressions.size(); if (credsNewExpressionCount > 0) { - // ToDo: Call importType agnostic addNamedModule - // addNamedModule(j, source, { - // importedName: v3ProviderName, - // v3ClientPackageName: "@aws-sdk/credential-provider", - // }); + addNamedModule(j, source, { + importType, + importedName: v3ProviderName, + packageName: "@aws-sdk/credential-providers", + }); credsNewExpressions.replaceWith(({ node }) => j.callExpression(j.identifier(v3ProviderName), node.arguments) ); diff --git a/src/transforms/v2-to-v3/modules/index.ts b/src/transforms/v2-to-v3/modules/index.ts index 70efb0f99..5a524ec1d 100644 --- a/src/transforms/v2-to-v3/modules/index.ts +++ b/src/transforms/v2-to-v3/modules/index.ts @@ -1,4 +1,5 @@ export * from "./addClientModules"; +export * from "./addNamedModule"; export * from "./getGlobalNameFromModule"; export * from "./getImportEqualsDeclarationType"; export * from "./getImportSpecifiers"; From 66a0215fdd20eaf4209b3d6ddea99d384b76bdeb Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:17:35 -0700 Subject: [PATCH 10/19] Support TemporaryCredentials --- .../v2-to-v3/__fixtures__/credentials/temp.input.js | 6 ++++++ .../v2-to-v3/__fixtures__/credentials/temp.output.js | 6 ++++++ src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts | 1 + 3 files changed, 13 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/temp.input.js create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/temp.output.js diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/temp.input.js b/src/transforms/v2-to-v3/__fixtures__/credentials/temp.input.js new file mode 100644 index 000000000..5ff1dc141 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/temp.input.js @@ -0,0 +1,6 @@ +import AWS from "aws-sdk"; + +const credentials = new AWS.ChainableTemporaryCredentials({ + params: { RoleArn: "RoleA" }, + masterCredentials: new AWS.EnvironmentCredentials("AWS"), +}); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/temp.output.js b/src/transforms/v2-to-v3/__fixtures__/credentials/temp.output.js new file mode 100644 index 000000000..b5755e882 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/temp.output.js @@ -0,0 +1,6 @@ +import { fromEnv, fromTemporaryCredentials } from "@aws-sdk/credential-providers"; + +const credentials = fromTemporaryCredentials({ + params: { RoleArn: "RoleA" }, + masterCredentials: fromEnv("AWS"), +}); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts index e2d4f810c..5e9ea9638 100644 --- a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts +++ b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts @@ -3,4 +3,5 @@ */ export const AWS_CREDENTIALS_MAP: Record = { EnvironmentCredentials: "fromEnv", + ChainableTemporaryCredentials: "fromTemporaryCredentials", }; From 9afdbd1ea7d0acab51baca90964e3c42689cabf0 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:18:17 -0700 Subject: [PATCH 11/19] chore: yarn changeset --- .changeset/hot-insects-protect.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/hot-insects-protect.md diff --git a/.changeset/hot-insects-protect.md b/.changeset/hot-insects-protect.md new file mode 100644 index 000000000..3b5ffb801 --- /dev/null +++ b/.changeset/hot-insects-protect.md @@ -0,0 +1,5 @@ +--- +"aws-sdk-js-codemod": minor +--- + +Basic transformation of AWS Credentials From db0629fb799a568d073aa2c5ae73a05d23df842a Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:25:44 -0700 Subject: [PATCH 12/19] Support EC2MetadataCredentials --- .../v2-to-v3/__fixtures__/credentials/ec2-metadata.input.js | 3 +++ .../v2-to-v3/__fixtures__/credentials/ec2-metadata.output.js | 3 +++ src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts | 1 + 3 files changed, 7 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.input.js create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.output.js diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.input.js b/src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.input.js new file mode 100644 index 000000000..cb9ab2a08 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.input.js @@ -0,0 +1,3 @@ +import AWS from "aws-sdk"; + +const credentials = new AWS.EC2MetadataCredentials(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.output.js b/src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.output.js new file mode 100644 index 000000000..ea013c028 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.output.js @@ -0,0 +1,3 @@ +import { fromInstanceMetadata } from "@aws-sdk/credential-providers"; + +const credentials = fromInstanceMetadata(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts index 5e9ea9638..55f1e2f54 100644 --- a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts +++ b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts @@ -2,6 +2,7 @@ * Maps the AWS credentials class name in v2 to the v3 equivalent provider. */ export const AWS_CREDENTIALS_MAP: Record = { + EC2MetadataCredentials: "fromInstanceMetadata", EnvironmentCredentials: "fromEnv", ChainableTemporaryCredentials: "fromTemporaryCredentials", }; From 4ab54596894e497b5d59549bfd48b7bdfef22815 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:28:11 -0700 Subject: [PATCH 13/19] Support ECSCredentials --- src/transforms/v2-to-v3/__fixtures__/credentials/ecs.input.js | 3 +++ src/transforms/v2-to-v3/__fixtures__/credentials/ecs.output.js | 3 +++ src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts | 1 + 3 files changed, 7 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/ecs.input.js create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/ecs.output.js diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/ecs.input.js b/src/transforms/v2-to-v3/__fixtures__/credentials/ecs.input.js new file mode 100644 index 000000000..8c94be923 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/ecs.input.js @@ -0,0 +1,3 @@ +import AWS from "aws-sdk"; + +const credentials = new AWS.ECSCredentials(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/ecs.output.js b/src/transforms/v2-to-v3/__fixtures__/credentials/ecs.output.js new file mode 100644 index 000000000..9f9f8a1ce --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/ecs.output.js @@ -0,0 +1,3 @@ +import { fromContainerMetadata } from "@aws-sdk/credential-providers"; + +const credentials = fromContainerMetadata(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts index 55f1e2f54..21b181fb8 100644 --- a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts +++ b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts @@ -3,6 +3,7 @@ */ export const AWS_CREDENTIALS_MAP: Record = { EC2MetadataCredentials: "fromInstanceMetadata", + ECSCredentials: "fromContainerMetadata", EnvironmentCredentials: "fromEnv", ChainableTemporaryCredentials: "fromTemporaryCredentials", }; From e5cd234af2bbe53cbbc30459fcdaa6988750ab2a Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:38:11 -0700 Subject: [PATCH 14/19] Add comment about credentials transformation --- .../__fixtures__/credentials/chainable.input.js | 6 ++++++ .../__fixtures__/credentials/chainable.output.js | 9 +++++++++ .../credentials/ec2-metadata.input.js | 2 +- .../credentials/ec2-metadata.output.js | 5 ++++- .../__fixtures__/credentials/ecs.input.js | 2 +- .../__fixtures__/credentials/ecs.output.js | 5 ++++- .../__fixtures__/credentials/env.input.js | 2 +- .../__fixtures__/credentials/env.output.js | 5 ++++- .../__fixtures__/credentials/temp.input.js | 6 ------ .../__fixtures__/credentials/temp.output.js | 6 ------ .../v2-to-v3/apis/replaceAwsCredentials.ts | 16 +++++++++++++++- 11 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/chainable.input.js create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/chainable.output.js delete mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/temp.input.js delete mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/temp.output.js diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/chainable.input.js b/src/transforms/v2-to-v3/__fixtures__/credentials/chainable.input.js new file mode 100644 index 000000000..22131ed18 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/chainable.input.js @@ -0,0 +1,6 @@ +import AWS from "aws-sdk"; + +new AWS.ChainableTemporaryCredentials({ + params: { RoleArn: "RoleA" }, + masterCredentials: existingCredentials, +}); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/chainable.output.js b/src/transforms/v2-to-v3/__fixtures__/credentials/chainable.output.js new file mode 100644 index 000000000..6b14ef394 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/chainable.output.js @@ -0,0 +1,9 @@ +import { fromTemporaryCredentials } from "@aws-sdk/credential-providers"; + +// JS SDK v3 switched to credential providers to functions instead of objects. +// This is the closest approximation from codemod of what your application needs. +// Reference: https://www.npmjs.com/package/@aws-sdk/credential-providers +fromTemporaryCredentials({ + params: { RoleArn: "RoleA" }, + masterCredentials: existingCredentials, +}); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.input.js b/src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.input.js index cb9ab2a08..ac8743e1d 100644 --- a/src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.input.js +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.input.js @@ -1,3 +1,3 @@ import AWS from "aws-sdk"; -const credentials = new AWS.EC2MetadataCredentials(); \ No newline at end of file +new AWS.EC2MetadataCredentials(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.output.js b/src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.output.js index ea013c028..ad9c9962e 100644 --- a/src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.output.js +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/ec2-metadata.output.js @@ -1,3 +1,6 @@ import { fromInstanceMetadata } from "@aws-sdk/credential-providers"; -const credentials = fromInstanceMetadata(); \ No newline at end of file +// JS SDK v3 switched to credential providers to functions instead of objects. +// This is the closest approximation from codemod of what your application needs. +// Reference: https://www.npmjs.com/package/@aws-sdk/credential-providers +fromInstanceMetadata(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/ecs.input.js b/src/transforms/v2-to-v3/__fixtures__/credentials/ecs.input.js index 8c94be923..4e03506d3 100644 --- a/src/transforms/v2-to-v3/__fixtures__/credentials/ecs.input.js +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/ecs.input.js @@ -1,3 +1,3 @@ import AWS from "aws-sdk"; -const credentials = new AWS.ECSCredentials(); \ No newline at end of file +new AWS.ECSCredentials(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/ecs.output.js b/src/transforms/v2-to-v3/__fixtures__/credentials/ecs.output.js index 9f9f8a1ce..6fa78f781 100644 --- a/src/transforms/v2-to-v3/__fixtures__/credentials/ecs.output.js +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/ecs.output.js @@ -1,3 +1,6 @@ import { fromContainerMetadata } from "@aws-sdk/credential-providers"; -const credentials = fromContainerMetadata(); \ No newline at end of file +// JS SDK v3 switched to credential providers to functions instead of objects. +// This is the closest approximation from codemod of what your application needs. +// Reference: https://www.npmjs.com/package/@aws-sdk/credential-providers +fromContainerMetadata(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/env.input.js b/src/transforms/v2-to-v3/__fixtures__/credentials/env.input.js index ed0dda65a..04ad48b82 100644 --- a/src/transforms/v2-to-v3/__fixtures__/credentials/env.input.js +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/env.input.js @@ -1,3 +1,3 @@ import AWS from "aws-sdk"; -const credentials = new AWS.EnvironmentCredentials("AWS"); \ No newline at end of file +new AWS.EnvironmentCredentials("AWS"); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/env.output.js b/src/transforms/v2-to-v3/__fixtures__/credentials/env.output.js index 0631bdda6..a8379d98d 100644 --- a/src/transforms/v2-to-v3/__fixtures__/credentials/env.output.js +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/env.output.js @@ -1,3 +1,6 @@ import { fromEnv } from "@aws-sdk/credential-providers"; -const credentials = fromEnv("AWS"); \ No newline at end of file +// JS SDK v3 switched to credential providers to functions instead of objects. +// This is the closest approximation from codemod of what your application needs. +// Reference: https://www.npmjs.com/package/@aws-sdk/credential-providers +fromEnv("AWS"); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/temp.input.js b/src/transforms/v2-to-v3/__fixtures__/credentials/temp.input.js deleted file mode 100644 index 5ff1dc141..000000000 --- a/src/transforms/v2-to-v3/__fixtures__/credentials/temp.input.js +++ /dev/null @@ -1,6 +0,0 @@ -import AWS from "aws-sdk"; - -const credentials = new AWS.ChainableTemporaryCredentials({ - params: { RoleArn: "RoleA" }, - masterCredentials: new AWS.EnvironmentCredentials("AWS"), -}); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/temp.output.js b/src/transforms/v2-to-v3/__fixtures__/credentials/temp.output.js deleted file mode 100644 index b5755e882..000000000 --- a/src/transforms/v2-to-v3/__fixtures__/credentials/temp.output.js +++ /dev/null @@ -1,6 +0,0 @@ -import { fromEnv, fromTemporaryCredentials } from "@aws-sdk/credential-providers"; - -const credentials = fromTemporaryCredentials({ - params: { RoleArn: "RoleA" }, - masterCredentials: fromEnv("AWS"), -}); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts b/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts index 05a2f47de..5333d6e2e 100644 --- a/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts +++ b/src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts @@ -29,7 +29,21 @@ export const replaceAwsCredentials = ( packageName: "@aws-sdk/credential-providers", }); credsNewExpressions.replaceWith(({ node }) => - j.callExpression(j.identifier(v3ProviderName), node.arguments) + j.callExpression.from({ + callee: j.identifier(v3ProviderName), + comments: [ + j.commentLine( + " JS SDK v3 switched to credential providers to functions instead of objects." + ), + j.commentLine( + " This is the closest approximation from codemod of what your application needs." + ), + j.commentLine( + " Reference: https://www.npmjs.com/package/@aws-sdk/credential-providers" + ), + ], + arguments: node.arguments, + }) ); } } From 2d47c9ab6ef5c65b5fcdd0ab354f7c1e599fbf6b Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:39:47 -0700 Subject: [PATCH 15/19] Support RemoteCredentials --- .../v2-to-v3/__fixtures__/credentials/remote.input.js | 3 +++ .../v2-to-v3/__fixtures__/credentials/remote.output.js | 6 ++++++ src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/remote.input.js create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/remote.output.js diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/remote.input.js b/src/transforms/v2-to-v3/__fixtures__/credentials/remote.input.js new file mode 100644 index 000000000..e39a498ff --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/remote.input.js @@ -0,0 +1,3 @@ +import AWS from "aws-sdk"; + +new AWS.RemoteCredentials(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/remote.output.js b/src/transforms/v2-to-v3/__fixtures__/credentials/remote.output.js new file mode 100644 index 000000000..6fa78f781 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/remote.output.js @@ -0,0 +1,6 @@ +import { fromContainerMetadata } from "@aws-sdk/credential-providers"; + +// JS SDK v3 switched to credential providers to functions instead of objects. +// This is the closest approximation from codemod of what your application needs. +// Reference: https://www.npmjs.com/package/@aws-sdk/credential-providers +fromContainerMetadata(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts index 21b181fb8..a51129358 100644 --- a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts +++ b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts @@ -2,8 +2,9 @@ * Maps the AWS credentials class name in v2 to the v3 equivalent provider. */ export const AWS_CREDENTIALS_MAP: Record = { + ChainableTemporaryCredentials: "fromTemporaryCredentials", EC2MetadataCredentials: "fromInstanceMetadata", ECSCredentials: "fromContainerMetadata", EnvironmentCredentials: "fromEnv", - ChainableTemporaryCredentials: "fromTemporaryCredentials", + RemoteCredentials: "fromContainerMetadata", }; From 6619509ff77011f9db8553cf961ad7b8f41ffc7f Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:42:09 -0700 Subject: [PATCH 16/19] Support SharedIniFileCredentials --- .../v2-to-v3/__fixtures__/credentials/ini.input.js | 3 +++ .../v2-to-v3/__fixtures__/credentials/ini.output.js | 6 ++++++ .../v2-to-v3/__fixtures__/misc/unsupported-feature.input.js | 5 ----- .../__fixtures__/misc/unsupported-feature.output.js | 5 ----- src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts | 1 + 5 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/ini.input.js create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/ini.output.js delete mode 100644 src/transforms/v2-to-v3/__fixtures__/misc/unsupported-feature.input.js delete mode 100644 src/transforms/v2-to-v3/__fixtures__/misc/unsupported-feature.output.js diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/ini.input.js b/src/transforms/v2-to-v3/__fixtures__/credentials/ini.input.js new file mode 100644 index 000000000..4ae024c40 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/ini.input.js @@ -0,0 +1,3 @@ +import AWS from "aws-sdk"; + +new AWS.SharedIniFileCredentials({ profile: "profile-name" }); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/ini.output.js b/src/transforms/v2-to-v3/__fixtures__/credentials/ini.output.js new file mode 100644 index 000000000..c9a48b28c --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/ini.output.js @@ -0,0 +1,6 @@ +import { fromIni } from "@aws-sdk/credential-providers"; + +// JS SDK v3 switched to credential providers to functions instead of objects. +// This is the closest approximation from codemod of what your application needs. +// Reference: https://www.npmjs.com/package/@aws-sdk/credential-providers +fromIni({ profile: "profile-name" }); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/misc/unsupported-feature.input.js b/src/transforms/v2-to-v3/__fixtures__/misc/unsupported-feature.input.js deleted file mode 100644 index 18667ea83..000000000 --- a/src/transforms/v2-to-v3/__fixtures__/misc/unsupported-feature.input.js +++ /dev/null @@ -1,5 +0,0 @@ -// ToDo: Update when transformation is added. -// Current test verifies error is not thrown. -import AWS from "aws-sdk"; - -const credentials = new AWS.SharedIniFileCredentials({ profile: "my-profile" }); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/misc/unsupported-feature.output.js b/src/transforms/v2-to-v3/__fixtures__/misc/unsupported-feature.output.js deleted file mode 100644 index 18667ea83..000000000 --- a/src/transforms/v2-to-v3/__fixtures__/misc/unsupported-feature.output.js +++ /dev/null @@ -1,5 +0,0 @@ -// ToDo: Update when transformation is added. -// Current test verifies error is not thrown. -import AWS from "aws-sdk"; - -const credentials = new AWS.SharedIniFileCredentials({ profile: "my-profile" }); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts index a51129358..a00e0eb5e 100644 --- a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts +++ b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts @@ -7,4 +7,5 @@ export const AWS_CREDENTIALS_MAP: Record = { ECSCredentials: "fromContainerMetadata", EnvironmentCredentials: "fromEnv", RemoteCredentials: "fromContainerMetadata", + SharedIniFileCredentials: "fromIni", }; From c356f93fa3a918b2587861bd99bd846f7f4e473e Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:40:12 -0700 Subject: [PATCH 17/19] Support TokenFileWebIdentityCredentials --- .../v2-to-v3/__fixtures__/credentials/token-file.input.js | 3 +++ .../v2-to-v3/__fixtures__/credentials/token-file.output.js | 6 ++++++ src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts | 1 + 3 files changed, 10 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/token-file.input.js create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/token-file.output.js diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/token-file.input.js b/src/transforms/v2-to-v3/__fixtures__/credentials/token-file.input.js new file mode 100644 index 000000000..cb6dd9c23 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/token-file.input.js @@ -0,0 +1,3 @@ +import AWS from "aws-sdk"; + +new AWS.TokenFileWebIdentityCredentials(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/token-file.output.js b/src/transforms/v2-to-v3/__fixtures__/credentials/token-file.output.js new file mode 100644 index 000000000..0c05cccaa --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/token-file.output.js @@ -0,0 +1,6 @@ +import { fromTokenFile } from "@aws-sdk/credential-providers"; + +// JS SDK v3 switched to credential providers to functions instead of objects. +// This is the closest approximation from codemod of what your application needs. +// Reference: https://www.npmjs.com/package/@aws-sdk/credential-providers +fromTokenFile(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts index a00e0eb5e..615f3d57a 100644 --- a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts +++ b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts @@ -8,4 +8,5 @@ export const AWS_CREDENTIALS_MAP: Record = { EnvironmentCredentials: "fromEnv", RemoteCredentials: "fromContainerMetadata", SharedIniFileCredentials: "fromIni", + TokenFileWebIdentityCredentials: "fromTokenFile", }; From c03e9ee9076596ddd805349c29b86efd088027f5 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:41:46 -0700 Subject: [PATCH 18/19] Support WebIdentityCredentials --- .../v2-to-v3/__fixtures__/credentials/token-web.input.js | 3 +++ .../v2-to-v3/__fixtures__/credentials/token-web.output.js | 6 ++++++ src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts | 1 + 3 files changed, 10 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/token-web.input.js create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/token-web.output.js diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/token-web.input.js b/src/transforms/v2-to-v3/__fixtures__/credentials/token-web.input.js new file mode 100644 index 000000000..e5a22dbdf --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/token-web.input.js @@ -0,0 +1,3 @@ +import AWS from "aws-sdk"; + +new AWS.WebIdentityCredentials(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/token-web.output.js b/src/transforms/v2-to-v3/__fixtures__/credentials/token-web.output.js new file mode 100644 index 000000000..210f24537 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/token-web.output.js @@ -0,0 +1,6 @@ +import { fromWebToken } from "@aws-sdk/credential-providers"; + +// JS SDK v3 switched to credential providers to functions instead of objects. +// This is the closest approximation from codemod of what your application needs. +// Reference: https://www.npmjs.com/package/@aws-sdk/credential-providers +fromWebToken(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts index 615f3d57a..1bf539b37 100644 --- a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts +++ b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts @@ -9,4 +9,5 @@ export const AWS_CREDENTIALS_MAP: Record = { RemoteCredentials: "fromContainerMetadata", SharedIniFileCredentials: "fromIni", TokenFileWebIdentityCredentials: "fromTokenFile", + WebIdentityCredentials: "fromWebToken", }; From 4d9a9b9c8d192176cdeaaf887115e6271023fc80 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:54:28 -0700 Subject: [PATCH 19/19] Support CognitoIdentityCredentials --- .../__fixtures__/credentials/cognito-identity.input.js | 3 +++ .../__fixtures__/credentials/cognito-identity.output.js | 6 ++++++ src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts | 1 + 3 files changed, 10 insertions(+) create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/cognito-identity.input.js create mode 100644 src/transforms/v2-to-v3/__fixtures__/credentials/cognito-identity.output.js diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/cognito-identity.input.js b/src/transforms/v2-to-v3/__fixtures__/credentials/cognito-identity.input.js new file mode 100644 index 000000000..5f7be3c97 --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/cognito-identity.input.js @@ -0,0 +1,3 @@ +import AWS from "aws-sdk"; + +new AWS.CognitoIdentityCredentials(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/credentials/cognito-identity.output.js b/src/transforms/v2-to-v3/__fixtures__/credentials/cognito-identity.output.js new file mode 100644 index 000000000..b81904f5d --- /dev/null +++ b/src/transforms/v2-to-v3/__fixtures__/credentials/cognito-identity.output.js @@ -0,0 +1,6 @@ +import { fromCognitoIdentity } from "@aws-sdk/credential-providers"; + +// JS SDK v3 switched to credential providers to functions instead of objects. +// This is the closest approximation from codemod of what your application needs. +// Reference: https://www.npmjs.com/package/@aws-sdk/credential-providers +fromCognitoIdentity(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts index 1bf539b37..e75303aa5 100644 --- a/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts +++ b/src/transforms/v2-to-v3/config/AWS_CREDENTIALS_MAP.ts @@ -3,6 +3,7 @@ */ export const AWS_CREDENTIALS_MAP: Record = { ChainableTemporaryCredentials: "fromTemporaryCredentials", + CognitoIdentityCredentials: "fromCognitoIdentity", EC2MetadataCredentials: "fromInstanceMetadata", ECSCredentials: "fromContainerMetadata", EnvironmentCredentials: "fromEnv",