-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass values from global config in service config (#667)
- Loading branch information
Showing
20 changed files
with
242 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"aws-sdk-js-codemod": minor | ||
--- | ||
|
||
Pass values from global config in service config |
7 changes: 7 additions & 0 deletions
7
src/transforms/v2-to-v3/__fixtures__/config-update/client.existing-config-overriden.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
AWS.config.update({ region: "us-west-2" }); | ||
|
||
const client = new AWS.DynamoDB({ | ||
region: "us-east-1" | ||
}); |
12 changes: 12 additions & 0 deletions
12
...transforms/v2-to-v3/__fixtures__/config-update/client.existing-config-overriden.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
import { DynamoDB } from "@aws-sdk/client-dynamodb"; | ||
|
||
// JS SDK v3 does not support global configuration. | ||
// Codemod has attempted to pass values to each service client in this file. | ||
// You may need to update clients outside of this file, if they use global config. | ||
AWS.config.update({ region: "us-west-2" }); | ||
|
||
const client = new DynamoDB({ | ||
region: "us-east-1" | ||
}); |
7 changes: 7 additions & 0 deletions
7
src/transforms/v2-to-v3/__fixtures__/config-update/client.existing-config.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
AWS.config.update({ region: "us-west-2" }); | ||
|
||
const client = new AWS.DynamoDB({ | ||
logger: console | ||
}); |
13 changes: 13 additions & 0 deletions
13
src/transforms/v2-to-v3/__fixtures__/config-update/client.existing-config.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
import { DynamoDB } from "@aws-sdk/client-dynamodb"; | ||
|
||
// JS SDK v3 does not support global configuration. | ||
// Codemod has attempted to pass values to each service client in this file. | ||
// You may need to update clients outside of this file, if they use global config. | ||
AWS.config.update({ region: "us-west-2" }); | ||
|
||
const client = new DynamoDB({ | ||
logger: console, | ||
region: "us-west-2" | ||
}); |
5 changes: 5 additions & 0 deletions
5
src/transforms/v2-to-v3/__fixtures__/config-update/client.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
AWS.config.update({ region: "us-west-2" }); | ||
|
||
const client = new AWS.DynamoDB(); |
12 changes: 12 additions & 0 deletions
12
src/transforms/v2-to-v3/__fixtures__/config-update/client.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
import { DynamoDB } from "@aws-sdk/client-dynamodb"; | ||
|
||
// JS SDK v3 does not support global configuration. | ||
// Codemod has attempted to pass values to each service client in this file. | ||
// You may need to update clients outside of this file, if they use global config. | ||
AWS.config.update({ region: "us-west-2" }); | ||
|
||
const client = new DynamoDB({ | ||
region: "us-west-2" | ||
}); |
7 changes: 7 additions & 0 deletions
7
...sforms/v2-to-v3/__fixtures__/config-update/constructor.existing-config-overriden.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
AWS.config.update({ region: "us-west-2" }); | ||
|
||
const client = new AWS.Config({ | ||
region: "us-east-1" | ||
}); |
10 changes: 10 additions & 0 deletions
10
...forms/v2-to-v3/__fixtures__/config-update/constructor.existing-config-overriden.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
// JS SDK v3 does not support global configuration. | ||
// Codemod has attempted to pass values to each service client in this file. | ||
// You may need to update clients outside of this file, if they use global config. | ||
AWS.config.update({ region: "us-west-2" }); | ||
|
||
const client = { | ||
region: "us-east-1" | ||
}; |
7 changes: 7 additions & 0 deletions
7
src/transforms/v2-to-v3/__fixtures__/config-update/constructor.existing-config.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
AWS.config.update({ region: "us-west-2" }); | ||
|
||
const client = new AWS.Config({ | ||
logger: console | ||
}); |
11 changes: 11 additions & 0 deletions
11
src/transforms/v2-to-v3/__fixtures__/config-update/constructor.existing-config.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
// JS SDK v3 does not support global configuration. | ||
// Codemod has attempted to pass values to each service client in this file. | ||
// You may need to update clients outside of this file, if they use global config. | ||
AWS.config.update({ region: "us-west-2" }); | ||
|
||
const client = { | ||
logger: console, | ||
region: "us-west-2" | ||
}; |
5 changes: 5 additions & 0 deletions
5
src/transforms/v2-to-v3/__fixtures__/config-update/constructor.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
AWS.config.update({ region: "us-west-2" }); | ||
|
||
const config = new AWS.Config(); |
10 changes: 10 additions & 0 deletions
10
src/transforms/v2-to-v3/__fixtures__/config-update/constructor.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
// JS SDK v3 does not support global configuration. | ||
// Codemod has attempted to pass values to each service client in this file. | ||
// You may need to update clients outside of this file, if they use global config. | ||
AWS.config.update({ region: "us-west-2" }); | ||
|
||
const config = { | ||
region: "us-west-2" | ||
}; |
46 changes: 46 additions & 0 deletions
46
src/transforms/v2-to-v3/client-instances/getAwsGlobalConfig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Collection, JSCodeshift, ObjectExpression } from "jscodeshift"; | ||
|
||
export const getAwsGlobalConfig = ( | ||
j: JSCodeshift, | ||
source: Collection<unknown>, | ||
v2GlobalName?: string | ||
): ObjectExpression => { | ||
const objectExpression = j.objectExpression([]); | ||
|
||
if (!v2GlobalName) return objectExpression; | ||
|
||
source | ||
.find(j.CallExpression, { | ||
callee: { | ||
type: "MemberExpression", | ||
object: { | ||
type: "MemberExpression", | ||
object: { type: "Identifier", name: v2GlobalName }, | ||
property: { type: "Identifier", name: "config" }, | ||
}, | ||
property: { type: "Identifier", name: "update" }, | ||
}, | ||
}) | ||
.filter( | ||
({ node }) => node.arguments.length === 1 && node.arguments[0].type === "ObjectExpression" | ||
) | ||
.forEach(({ node }) => { | ||
const objectExpressionProperties = (node.arguments[0] as ObjectExpression).properties; | ||
|
||
objectExpressionProperties.forEach((property) => { | ||
objectExpression.properties.push(property); | ||
}); | ||
|
||
const comments = node.comments || []; | ||
comments.push( | ||
j.commentLine(" JS SDK v3 does not support global configuration."), | ||
j.commentLine(" Codemod has attempted to pass values to each service client in this file."), | ||
j.commentLine( | ||
" You may need to update clients outside of this file, if they use global config." | ||
) | ||
); | ||
node.comments = comments; | ||
}); | ||
|
||
return objectExpression; | ||
}; |
20 changes: 16 additions & 4 deletions
20
src/transforms/v2-to-v3/client-instances/getNewClientExpression.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./getAwsGlobalConfig"; | ||
export * from "./replaceAwsConfig"; | ||
export * from "./replaceClientCreation"; | ||
export * from "./replaceDocClientCreation"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters