-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathConvertSDKRequests.java
More file actions
144 lines (139 loc) · 5.39 KB
/
ConvertSDKRequests.java
File metadata and controls
144 lines (139 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package software.amazon.encryption.s3.internal;
import software.amazon.awssdk.services.s3.model.ChecksumType;
import software.amazon.awssdk.services.s3.model.CreateMultipartUploadRequest;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import java.time.Instant;
import java.util.Map;
public class ConvertSDKRequests {
public static CreateMultipartUploadRequest convert(PutObjectRequest request) {
final CreateMultipartUploadRequest.Builder output = CreateMultipartUploadRequest.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;
case "ChecksumType":
output.checksumType((ChecksumType) value);
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":
// The PutObjectRequest.builder().metadata(value)
// only takes Map<String, String> therefore it should not be possible
// to get here with anything other than a Map<String, String>
// This may be overkill, but this map should be small
// so the performance hit to verify this is worth the correctness.
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;
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;
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("Unknown PutObjectRequest field " + f.locationName() + ".");
}
}
});
return output
// OverrideConfiguration is not as SDKField but still needs to be supported
.overrideConfiguration(request.overrideConfiguration().orElse(null))
.build();
}
private static boolean isStringStringMap(Object value) {
if (!(value instanceof Map)) {
return false;
}
Map<?, ?> map = (Map<?, ?>) value;
return map.entrySet().stream()
.allMatch(entry -> entry != null
&& ((Map.Entry<?, ?>) entry).getKey() instanceof String
&& ((Map.Entry<?, ?>) entry).getValue() instanceof String);
}
}