Skip to content

Migration Tool - PutObjectRequest setters #6001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
package foo.bar;

import com.amazonaws.HttpMethod;
import com.amazonaws.services.s3.model.SSEAwsKeyManagementParams;
import com.amazonaws.services.s3.model.SSECustomerKey;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.Date;
import software.amazon.awssdk.core.async.AsyncRequestBody;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.AccessControlPolicy;
import software.amazon.awssdk.services.s3.model.GeneratePresignedUrlRequest;
import software.amazon.awssdk.services.s3.model.HeadObjectResponse;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
Expand All @@ -32,33 +35,49 @@ public class S3Transforms {

void upload_streamWithLiteralLength(S3TransferManager tm, String bucket, String key) {
HeadObjectResponse metadata = HeadObjectResponse.builder()
.build();
.build();
InputStream inputStream = new ByteArrayInputStream(("HelloWorld").getBytes());
PutObjectRequest requestWithStreamAndLiteralLength = PutObjectRequest.builder().bucket(bucket).key(key).websiteRedirectLocation("location").contentLength(333L)
.build();
.build();
/*AWS SDK for Java v2 migration: When using InputStream to upload with TransferManager, you must specify Content-Length and ExecutorService.*/tm.upload(UploadRequest.builder().putObjectRequest(requestWithStreamAndLiteralLength).requestBody(AsyncRequestBody.fromInputStream(inputStream, 333, newExecutorServiceVariableToDefine)).build());
}

void upload_streamWithAssignedLength(S3TransferManager tm, String bucket, String key) {
HeadObjectResponse metadata = HeadObjectResponse.builder()
.build();
.build();
long contentLen = 777;
InputStream inputStream = new ByteArrayInputStream(("HelloWorld").getBytes());
PutObjectRequest requestWithStreamAndAssignedLength = PutObjectRequest.builder().bucket(bucket).key(key).websiteRedirectLocation("location").contentLength(contentLen)
.build();
.build();
/*AWS SDK for Java v2 migration: When using InputStream to upload with TransferManager, you must specify Content-Length and ExecutorService.*/tm.upload(UploadRequest.builder().putObjectRequest(requestWithStreamAndAssignedLength).requestBody(AsyncRequestBody.fromInputStream(inputStream, contentLen, newExecutorServiceVariableToDefine)).build());
}

void upload_streamWithoutLength(S3TransferManager tm, String bucket, String key) {
InputStream inputStream = new ByteArrayInputStream(("HelloWorld").getBytes());
PutObjectRequest requestWithStreamAndNoLength = PutObjectRequest.builder().bucket(bucket).key(key).websiteRedirectLocation("location")
.build();
.build();
/*AWS SDK for Java v2 migration: When using InputStream to upload with TransferManager, you must specify Content-Length and ExecutorService.*/tm.upload(UploadRequest.builder().putObjectRequest(requestWithStreamAndNoLength).requestBody(AsyncRequestBody.fromInputStream(inputStream, -1L, newExecutorServiceVariableToDefine)).build());
}

void putObjectRequest_unsupportedSetters() {
SSECustomerKey sseCustomerKey = new SSECustomerKey("val");
SSEAwsKeyManagementParams sseParams = new SSEAwsKeyManagementParams();
AccessControlPolicy accessControlList = AccessControlPolicy.builder()
.build();

PutObjectRequest request = /*AWS SDK for Java v2 migration: Transform for PutObjectRequest setter accessControlList is not supported, please manually migrate your code to use the v2 setters: acl, grantReadACP, grantWriteACP - https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/model/PutObjectRequest.Builder.html#acl(java.lang.String)*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an easy way to combine all comments for a method invocation into the same comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I can think of. We'd have to retrieve and parse the comment. Seems better to put on separate lines especially with the links to javadocs.

/*AWS SDK for Java v2 migration: Transform for PutObjectRequest setter sseCustomerKey is not supported, please manually migrate your code to use the v2 setters: sseCustomerKey, sseCustomerKeyMD5 - https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/model/PutObjectRequest.Builder.html#sseCustomerKey(java.lang.String)*/
/*AWS SDK for Java v2 migration: Transform for PutObjectRequest setter sseAwsKeyManagementParam is not supported, please manually migrate your code to use the v2 setters: ssekmsKeyId, serverSideEncryption, sseCustomerAlgorithm - https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/model/PutObjectRequest.Builder.html#ssekmsKeyId(java.lang.String)*/
PutObjectRequest.builder().bucket("bucket").key("key").websiteRedirectLocation("location")
.sseCustomerKey(sseCustomerKey)
.sseAwsKeyManagementParams(sseParams)
.accessControlList(accessControlList)
.build();
}

void objectmetadata_unsupportedSetters(Date dateVal) {
HeadObjectResponse metadata = HeadObjectResponse.builder()
.build();
.build();

/*AWS SDK for Java v2 migration: Transform for ObjectMetadata setter - expirationTimeRuleId - is not supported, please manually migrate the code by setting it on the v2 request/response object.*/metadata.expirationTimeRuleId("expirationTimeRuleId");
/*AWS SDK for Java v2 migration: Transform for ObjectMetadata setter - ongoingRestore - is not supported, please manually migrate the code by setting it on the v2 request/response object.*/metadata.ongoingRestore(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

import com.amazonaws.HttpMethod;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.AccessControlList;
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.SSEAwsKeyManagementParams;
import com.amazonaws.services.s3.model.SSECustomerKey;
import com.amazonaws.services.s3.transfer.TransferManager;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand Down Expand Up @@ -54,6 +57,17 @@ void upload_streamWithoutLength(TransferManager tm, String bucket, String key) {
tm.upload(requestWithStreamAndNoLength);
}

void putObjectRequest_unsupportedSetters() {
SSECustomerKey sseCustomerKey = new SSECustomerKey("val");
SSEAwsKeyManagementParams sseParams = new SSEAwsKeyManagementParams();
AccessControlList accessControlList = new AccessControlList();

PutObjectRequest request = new PutObjectRequest("bucket", "key", "location")
.withSSECustomerKey(sseCustomerKey)
.withSSEAwsKeyManagementParams(sseParams)
.withAccessControlList(accessControlList);
}

void objectmetadata_unsupportedSetters(Date dateVal) {
ObjectMetadata metadata = new ObjectMetadata();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,22 +409,26 @@ private void s3Uri(URI uri, String uriAsString) {
}

private void generatePresignedUrl(S3Client s3, String bucket, String key, Date expiration) {
URL urlGet1 = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/S3Presigner.builder().s3Client(s3).build()
URL urlGet1 = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/
S3Presigner.builder().s3Client(s3).build()
.presignGetObject(p -> p.getObjectRequest(r -> r.bucket(bucket).key(key))
.signatureDuration(Duration.between(Instant.now(), expiration.toInstant())))
.url();

URL urlPut = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/S3Presigner.builder().s3Client(s3).build()
URL urlPut = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/
S3Presigner.builder().s3Client(s3).build()
.presignPutObject(p -> p.putObjectRequest(r -> r.bucket(bucket).key(key))
.signatureDuration(Duration.between(Instant.now(), expiration.toInstant())))
.url();

URL urlGet2 = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/S3Presigner.builder().s3Client(s3).build()
URL urlGet2 = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/
S3Presigner.builder().s3Client(s3).build()
.presignGetObject(p -> p.getObjectRequest(r -> r.bucket(bucket).key(key))
.signatureDuration(Duration.between(Instant.now(), expiration.toInstant())))
.url();

URL urlDelete = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/S3Presigner.builder().s3Client(s3).build()
URL urlDelete = /*AWS SDK for Java v2 migration: If generating multiple pre-signed URLs, it is recommended to create a single instance of S3Presigner, since creating a presigner can be expensive. If applicable, please manually refactor the transformed code.*/
S3Presigner.builder().s3Client(s3).build()
.presignDeleteObject(p -> p.deleteObjectRequest(r -> r.bucket(bucket).key(key))
.signatureDuration(Duration.between(Instant.now(), expiration.toInstant())))
.url();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import software.amazon.awssdk.core.ResponseInputStream;
import software.amazon.awssdk.core.sync.RequestBody;
Expand All @@ -30,6 +32,8 @@
import software.amazon.awssdk.services.s3.model.ObjectCannedACL;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.RequestPayer;
import software.amazon.awssdk.services.s3.model.Tag;
import software.amazon.awssdk.services.s3.model.Tagging;

public class S3Streaming {

Expand Down Expand Up @@ -61,6 +65,8 @@ void putObject_bucketKeyStreamMetadata(String bucket, String key, InputStream st
HeadObjectResponse metadataWithoutLength = HeadObjectResponse.builder()
.build();
/*AWS SDK for Java v2 migration: When using InputStream to upload with S3Client, Content-Length should be specified and used with RequestBody.fromInputStream(). Otherwise, the entire stream will be buffered in memory. If content length must be unknown, we recommend using the CRT-based S3 client - https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/crt-based-s3-client.html*/s3.putObject(PutObjectRequest.builder().bucket(bucket).key(key).build(), RequestBody.fromContentProvider(() -> stream, "application/octet-stream"));

/*AWS SDK for Java v2 migration: When using InputStream to upload with S3Client, Content-Length should be specified and used with RequestBody.fromInputStream(). Otherwise, the entire stream will be buffered in memory. If content length must be unknown, we recommend using the CRT-based S3 client - https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/crt-based-s3-client.html*/s3.putObject(PutObjectRequest.builder().bucket("bucket").key("key").build(), RequestBody.fromContentProvider(() -> stream, "application/octet-stream"));
}

/**
Expand Down Expand Up @@ -108,10 +114,16 @@ void putObject_requestPojoWithoutPayload(String bucket, String key) {


void putObjectSetters() {
List<Tag> tags = new ArrayList<>();
Tagging objectTagging = Tagging.builder().tagSet(tags)
.build();

PutObjectRequest putObjectRequest =
PutObjectRequest.builder().bucket("bucket").key("key").websiteRedirectLocation("location")
.bucket("bucketName")
.websiteRedirectLocation("redirectLocation")
.acl(ObjectCannedACL.AWS_EXEC_READ)
.tagging(objectTagging)
.build();
}

Expand Down Expand Up @@ -160,7 +172,7 @@ void putObjectRequest_withMetadata() {
.build();
}

void putObjectRequester_emptyMetadata() {
void putObjectRequest_emptyMetadata() {
HeadObjectResponse emptyMetadata1 = HeadObjectResponse.builder()
.build();
PutObjectRequest request1 =PutObjectRequest.builder().bucket("bucket").key("key").websiteRedirectLocation("location")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.ObjectTagging;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.Tag;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class S3Streaming {
Expand Down Expand Up @@ -53,6 +57,8 @@ void putObject_bucketKeyStreamMetadata(String bucket, String key, InputStream st

ObjectMetadata metadataWithoutLength = new ObjectMetadata();
s3.putObject(bucket, key, stream, metadataWithoutLength);

s3.putObject("bucket", "key", stream, new ObjectMetadata());
}

/**
Expand Down Expand Up @@ -95,10 +101,15 @@ void putObject_requestPojoWithoutPayload(String bucket, String key) {


void putObjectSetters() {
List<Tag> tags = new ArrayList<>();
ObjectTagging objectTagging = new ObjectTagging(tags);

PutObjectRequest putObjectRequest =
new PutObjectRequest("bucket", "key", "location")
.withBucketName("bucketName")
.withCannedAcl(CannedAccessControlList.AwsExecRead);
.withBucketName("bucketName")
.withRedirectLocation("redirectLocation")
.withCannedAcl(CannedAccessControlList.AwsExecRead)
.withTagging(objectTagging);
}

void putObjectRequesterPaysSetter() {
Expand Down Expand Up @@ -141,7 +152,7 @@ void putObjectRequest_withMetadata() {
PutObjectRequest request = new PutObjectRequest("bucket", "key", "location").withMetadata(metadata);
}

void putObjectRequester_emptyMetadata() {
void putObjectRequest_emptyMetadata() {
ObjectMetadata emptyMetadata1 = new ObjectMetadata();
PutObjectRequest request1 = new PutObjectRequest("bucket", "key", "location").withMetadata(emptyMetadata1);

Expand Down
Loading
Loading