|
12 | 12 |
|
13 | 13 | public class ConvertSDKRequests { |
14 | 14 |
|
| 15 | + public static PutObjectRequest convertRequest(CreateMultipartUploadRequest request) { |
| 16 | + |
| 17 | + final PutObjectRequest.Builder output = PutObjectRequest.builder(); |
| 18 | + request |
| 19 | + .toBuilder() |
| 20 | + .sdkFields() |
| 21 | + .forEach(f -> { |
| 22 | + final Object value = f.getValueOrDefault(request); |
| 23 | + if (value != null) { |
| 24 | + switch (f.memberName()) { |
| 25 | + case "ACL": |
| 26 | + output.acl((String) value); |
| 27 | + break; |
| 28 | + case "Bucket": |
| 29 | + output.bucket((String) value); |
| 30 | + break; |
| 31 | + case "BucketKeyEnabled": |
| 32 | + output.bucketKeyEnabled((Boolean) value); |
| 33 | + break; |
| 34 | + case "CacheControl": |
| 35 | + output.cacheControl((String) value); |
| 36 | + break; |
| 37 | + case "ChecksumAlgorithm": |
| 38 | + output.checksumAlgorithm((String) value); |
| 39 | + break; |
| 40 | + case "ContentDisposition": |
| 41 | + assert value instanceof String; |
| 42 | + output.contentDisposition((String) value); |
| 43 | + break; |
| 44 | + case "ContentEncoding": |
| 45 | + output.contentEncoding((String) value); |
| 46 | + break; |
| 47 | + case "ContentLanguage": |
| 48 | + output.contentLanguage((String) value); |
| 49 | + break; |
| 50 | + case "ContentType": |
| 51 | + output.contentType((String) value); |
| 52 | + break; |
| 53 | + case "ExpectedBucketOwner": |
| 54 | + output.expectedBucketOwner((String) value); |
| 55 | + break; |
| 56 | + case "Expires": |
| 57 | + output.expires((Instant) value); |
| 58 | + break; |
| 59 | + case "GrantFullControl": |
| 60 | + output.grantFullControl((String) value); |
| 61 | + break; |
| 62 | + case "GrantRead": |
| 63 | + output.grantRead((String) value); |
| 64 | + break; |
| 65 | + case "GrantReadACP": |
| 66 | + output.grantReadACP((String) value); |
| 67 | + break; |
| 68 | + case "GrantWriteACP": |
| 69 | + output.grantWriteACP((String) value); |
| 70 | + break; |
| 71 | + case "Key": |
| 72 | + output.key((String) value); |
| 73 | + break; |
| 74 | + case "Metadata": |
| 75 | + if (!isStringStringMap(value)) { |
| 76 | + throw new IllegalArgumentException("Metadata must be a Map<String, String>"); |
| 77 | + } |
| 78 | + @SuppressWarnings("unchecked") |
| 79 | + Map<String, String> metadata = (Map<String, String>) value; |
| 80 | + output.metadata(metadata); |
| 81 | + break; |
| 82 | + case "ObjectLockLegalHoldStatus": |
| 83 | + output.objectLockLegalHoldStatus((String) value); |
| 84 | + break; |
| 85 | + case "ObjectLockMode": |
| 86 | + output.objectLockMode((String) value); |
| 87 | + break; |
| 88 | + case "ObjectLockRetainUntilDate": |
| 89 | + output.objectLockRetainUntilDate((Instant) value); |
| 90 | + break; |
| 91 | + case "RequestPayer": |
| 92 | + output.requestPayer((String) value); |
| 93 | + break; |
| 94 | + case "ServerSideEncryption": |
| 95 | + output.serverSideEncryption((String) value); |
| 96 | + break; |
| 97 | + case "SSECustomerAlgorithm": |
| 98 | + output.sseCustomerAlgorithm((String) value); |
| 99 | + break; |
| 100 | + case "SSECustomerKey": |
| 101 | + output.sseCustomerKey((String) value); |
| 102 | + break; |
| 103 | + case "SSEKMSEncryptionContext": |
| 104 | + output.ssekmsEncryptionContext((String) value); |
| 105 | + break; |
| 106 | + case "SSEKMSKeyId": |
| 107 | + output.ssekmsKeyId((String) value); |
| 108 | + break; |
| 109 | + case "StorageClass": |
| 110 | + output.storageClass((String) value); |
| 111 | + break; |
| 112 | + case "Tagging": |
| 113 | + output.tagging((String) value); |
| 114 | + break; |
| 115 | + case "WebsiteRedirectLocation": |
| 116 | + output.websiteRedirectLocation((String) value); |
| 117 | + break; |
| 118 | + default: |
| 119 | + // Rather than silently dropping the value, |
| 120 | + // we loudly signal that we don't know how to handle this field. |
| 121 | + throw new IllegalArgumentException( |
| 122 | + f.locationName() + " is an unknown field. " + |
| 123 | + "The S3 Encryption Client does not recognize this option and cannot set it on the PutObjectRequest." + |
| 124 | + "This may be a new S3 feature." + |
| 125 | + "Please report this to the Amazon S3 Encryption Client for Java: " + |
| 126 | + "https://github.com/aws/amazon-s3-encryption-client-java/issues." + |
| 127 | + "To work around this issue you can disable multi part upload," + |
| 128 | + "use the Async client, or not set this value on PutObject." + |
| 129 | + "You may be able to update this value after the PutObject request completes." |
| 130 | + ); |
| 131 | + } |
| 132 | + } |
| 133 | + }); |
| 134 | + return output |
| 135 | + // OverrideConfiguration is not as SDKField but still needs to be supported |
| 136 | + .overrideConfiguration(request.overrideConfiguration().orElse(null)) |
| 137 | + .build(); |
| 138 | + } |
| 139 | + |
15 | 140 | public static CreateMultipartUploadRequest convertRequest(PutObjectRequest request) { |
16 | 141 |
|
17 | 142 | final CreateMultipartUploadRequest.Builder output = CreateMultipartUploadRequest.builder(); |
|
0 commit comments