-
Notifications
You must be signed in to change notification settings - Fork 16
feat: put object with instruction file configured #466
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
base: main
Are you sure you want to change the base?
Changes from all commits
8e51328
898c55e
fd64f1c
95b3b5a
3546538
ed761d9
a34b347
d6da2cf
60feafd
288ee65
9c1c50d
ae6b6b4
c9378cf
ef353d7
fbdbe92
9e25d8f
7bf259c
ff5e99c
a396a7c
b1c0898
b4b2047
b9ae158
4f51c42
bf2be6e
02f6f48
c319d44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,146 @@ | |
|
||
public class ConvertSDKRequests { | ||
|
||
/** | ||
* Converts a CreateMultipartUploadRequest to a PutObjectRequest. This conversion is necessary when | ||
* Instruction File PutObject is enabled and a multipart upload is performed.The method copies all the | ||
* relevant fields from the CreateMultipartUploadRequest to the PutObjectRequest. | ||
* @param request The CreateMultipartUploadRequest to convert | ||
* @return The converted PutObjectRequest | ||
* @throws IllegalArgumentException if the request contains an invalid field | ||
*/ | ||
public static PutObjectRequest convertRequest(CreateMultipartUploadRequest request) { | ||
final PutObjectRequest.Builder output = PutObjectRequest.builder(); | ||
request | ||
.toBuilder() | ||
.sdkFields() | ||
.forEach(f -> { | ||
final Object value = f.getValueOrDefault(request); | ||
if (value != null) { | ||
switch (f.memberName()) { | ||
case "ACL": | ||
output.acl((String) value); | ||
break; | ||
case "Bucket": | ||
output.bucket((String) value); | ||
break; | ||
case "BucketKeyEnabled": | ||
output.bucketKeyEnabled((Boolean) value); | ||
break; | ||
case "CacheControl": | ||
output.cacheControl((String) value); | ||
break; | ||
case "ChecksumAlgorithm": | ||
output.checksumAlgorithm((String) value); | ||
break; | ||
Comment on lines
+44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see some field |
||
case "ContentDisposition": | ||
assert value instanceof String; | ||
output.contentDisposition((String) value); | ||
break; | ||
case "ContentEncoding": | ||
output.contentEncoding((String) value); | ||
break; | ||
case "ContentLanguage": | ||
output.contentLanguage((String) value); | ||
break; | ||
case "ContentType": | ||
output.contentType((String) value); | ||
break; | ||
case "ExpectedBucketOwner": | ||
output.expectedBucketOwner((String) value); | ||
break; | ||
case "Expires": | ||
output.expires((Instant) value); | ||
break; | ||
case "GrantFullControl": | ||
output.grantFullControl((String) value); | ||
break; | ||
case "GrantRead": | ||
output.grantRead((String) value); | ||
break; | ||
case "GrantReadACP": | ||
output.grantReadACP((String) value); | ||
break; | ||
case "GrantWriteACP": | ||
output.grantWriteACP((String) value); | ||
break; | ||
case "Key": | ||
output.key((String) value); | ||
break; | ||
case "Metadata": | ||
if (!isStringStringMap(value)) { | ||
throw new IllegalArgumentException("Metadata must be a Map<String, String>"); | ||
} | ||
@SuppressWarnings("unchecked") | ||
Map<String, String> metadata = (Map<String, String>) value; | ||
output.metadata(metadata); | ||
break; | ||
case "ObjectLockLegalHoldStatus": | ||
output.objectLockLegalHoldStatus((String) value); | ||
break; | ||
case "ObjectLockMode": | ||
output.objectLockMode((String) value); | ||
break; | ||
Comment on lines
+92
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just checking: we don't need to copy the |
||
case "ObjectLockRetainUntilDate": | ||
output.objectLockRetainUntilDate((Instant) value); | ||
break; | ||
case "RequestPayer": | ||
output.requestPayer((String) value); | ||
break; | ||
case "ServerSideEncryption": | ||
output.serverSideEncryption((String) value); | ||
break; | ||
case "SSECustomerAlgorithm": | ||
output.sseCustomerAlgorithm((String) value); | ||
break; | ||
case "SSECustomerKey": | ||
output.sseCustomerKey((String) value); | ||
break; | ||
Comment on lines
+107
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need |
||
case "SSEKMSEncryptionContext": | ||
output.ssekmsEncryptionContext((String) value); | ||
break; | ||
case "SSEKMSKeyId": | ||
output.ssekmsKeyId((String) value); | ||
break; | ||
case "StorageClass": | ||
output.storageClass((String) value); | ||
break; | ||
case "Tagging": | ||
output.tagging((String) value); | ||
break; | ||
case "WebsiteRedirectLocation": | ||
output.websiteRedirectLocation((String) value); | ||
break; | ||
default: | ||
// Rather than silently dropping the value, | ||
// we loudly signal that we don't know how to handle this field. | ||
throw new IllegalArgumentException( | ||
f.memberName() + " is an unknown field. " + | ||
"The S3 Encryption Client does not recognize this option and cannot set it on the PutObjectRequest." + | ||
"This may be a new S3 feature." + | ||
"Please report this to the Amazon S3 Encryption Client for Java: " + | ||
"https://github.com/aws/amazon-s3-encryption-client-java/issues." + | ||
"To work around this issue, you can disable Instruction File on PutObject or disable" + | ||
"multi part upload, or use the Async client, or not set this value on PutObject." + | ||
"You may be able to update this value after the PutObject request completes." | ||
); | ||
} | ||
} | ||
}); | ||
return output | ||
// OverrideConfiguration is not as SDKField but still needs to be supported | ||
.overrideConfiguration(request.overrideConfiguration().orElse(null)) | ||
.build(); | ||
} | ||
/** | ||
* Converts a PutObjectRequest to CreateMultipartUploadRequest.This conversion is necessary to convert an | ||
* original PutObjectRequest into a CreateMultipartUploadRequest to initiate the | ||
* multipart upload while maintaining the original request's configuration. | ||
* @param request The PutObjectRequest to convert | ||
* @return The converted CreateMultipartUploadRequest | ||
* @throws IllegalArgumentException if the request contains an invalid field | ||
*/ | ||
public static CreateMultipartUploadRequest convertRequest(PutObjectRequest request) { | ||
|
||
final CreateMultipartUploadRequest.Builder output = CreateMultipartUploadRequest.builder(); | ||
request | ||
.toBuilder() | ||
|
@@ -126,7 +264,7 @@ public static CreateMultipartUploadRequest convertRequest(PutObjectRequest reque | |
// Rather than silently dropping the value, | ||
// we loudly signal that we don't know how to handle this field. | ||
throw new IllegalArgumentException( | ||
f.locationName() + " is an unknown field. " + | ||
f.memberName() + " is an unknown field. " + | ||
"The S3 Encryption Client does not recognize this option and cannot set it on the CreateMultipartUploadRequest." + | ||
"This may be a new S3 feature." + | ||
"Please report this to the Amazon S3 Encryption Client for Java: " + | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We should add some comments here, i.e. that this is used to set the optional fields for Instruction File puts when the request is a multipart upload, because the instruction file is Put with an ordinary PutObject request.
And likewise for the other
convertRequest
method which is used to set the optional fields on high-level Multipart PutObject requests.