-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add transformation for s3 createPresignedPost (#863)
- Loading branch information
Showing
11 changed files
with
98 additions
and
0 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 | ||
--- | ||
|
||
Add transformation for s3 createPresignedPost |
8 changes: 8 additions & 0 deletions
8
src/transforms/v2-to-v3/__fixtures__/s3-presigned-post/callback.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,8 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
const s3 = new AWS.S3(); | ||
const params = { Bucket: "bucket", Fields: { key: "key" } }; | ||
|
||
s3.createPresignedPost(params, function (err, data) { | ||
console.log('The URL is', data.url); | ||
}); |
10 changes: 10 additions & 0 deletions
10
src/transforms/v2-to-v3/__fixtures__/s3-presigned-post/callback.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"; | ||
|
||
const s3 = new AWS.S3(); | ||
const params = { Bucket: "bucket", Fields: { key: "key" } }; | ||
|
||
// S3 createPresignedPost with callbacks is not supported in AWS SDK for JavaScript (v3). | ||
// Please convert to 'client.createPresignedPost(params)', and re-run aws-sdk-js-codemod. | ||
s3.createPresignedPost(params, function (err, data) { | ||
console.log('The URL is', data.url); | ||
}); |
4 changes: 4 additions & 0 deletions
4
src/transforms/v2-to-v3/__fixtures__/s3-presigned-post/createPresignedPost.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,4 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
const client = new AWS.S3(); | ||
const response = client.createPresignedPost(params); |
5 changes: 5 additions & 0 deletions
5
src/transforms/v2-to-v3/__fixtures__/s3-presigned-post/createPresignedPost.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,5 @@ | ||
import { createPresignedPost } from "@aws-sdk/s3-presigned-post"; | ||
import { S3 } from "@aws-sdk/client-s3"; | ||
|
||
const client = new S3(); | ||
const response = await createPresignedPost(client, params); |
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
24 changes: 24 additions & 0 deletions
24
src/transforms/v2-to-v3/apis/isS3CreatePresignedPostApiUsed.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,24 @@ | ||
import { Collection, JSCodeshift } from "jscodeshift"; | ||
|
||
import { ClientIdentifier } from "../types"; | ||
|
||
export const isS3CreatePresignedPostApiUsed = ( | ||
j: JSCodeshift, | ||
source: Collection<unknown>, | ||
clientIdentifiers: ClientIdentifier[] | ||
) => { | ||
for (const clientId of clientIdentifiers) { | ||
if ( | ||
source.find(j.CallExpression, { | ||
callee: { | ||
type: "MemberExpression", | ||
object: clientId, | ||
property: { type: "Identifier", name: "createPresignedPost" }, | ||
}, | ||
}).length | ||
) | ||
return true; | ||
} | ||
|
||
return false; | ||
}; |
24 changes: 24 additions & 0 deletions
24
src/transforms/v2-to-v3/apis/replaceS3CreatePresignedPostApi.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,24 @@ | ||
import { Collection, JSCodeshift } from "jscodeshift"; | ||
|
||
import { ClientIdentifier } from "../types"; | ||
import { getClientApiCallExpression } from "./getClientApiCallExpression"; | ||
|
||
// Updates `s3.createPresignedPost(params)` API with `await createPresignedPost(s3, params)` API. | ||
export const replaceS3CreatePresignedPostApi = ( | ||
j: JSCodeshift, | ||
source: Collection<unknown>, | ||
clientIdentifiers: ClientIdentifier[] | ||
): void => { | ||
for (const clientId of clientIdentifiers) { | ||
source | ||
.find(j.CallExpression, getClientApiCallExpression(clientId, "createPresignedPost")) | ||
.replaceWith((callExpression) => | ||
j.awaitExpression.from({ | ||
argument: j.callExpression.from({ | ||
callee: j.identifier("createPresignedPost"), | ||
arguments: [clientId, callExpression.node.arguments[0]], | ||
}), | ||
}) | ||
); | ||
} | ||
}; |
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