1
1
package software .amazon .payloadoffloading ;
2
2
3
- import com .amazonaws .AmazonClientException ;
4
- import com .amazonaws .annotation .NotThreadSafe ;
5
- import com .amazonaws .services .s3 .AmazonS3 ;
6
- import com .amazonaws .services .s3 .model .SSEAwsKeyManagementParams ;
7
- import org .apache .commons .logging .Log ;
8
- import org .apache .commons .logging .LogFactory ;
3
+ import org .slf4j .Logger ;
4
+ import org .slf4j .LoggerFactory ;
5
+ import software .amazon .awssdk .annotations .NotThreadSafe ;
6
+ import software .amazon .awssdk .core .exception .SdkClientException ;
7
+ import software .amazon .awssdk .services .s3 .S3Client ;
9
8
10
9
/**
11
- * Amazon payload storage configuration options such as Amazon S3 client,
12
- * bucket name, and payload size threshold for payloads.
10
+ * <p>Amazon payload storage configuration options such as Amazon S3 client,
11
+ * bucket name, and payload size threshold for payloads.</p>
12
+ *
13
+ * <p>Server side encryption is optional and can be enabled using with {@link #withServerSideEncryption(ServerSideEncryptionStrategy)}
14
+ * or {@link #setServerSideEncryptionStrategy(ServerSideEncryptionStrategy)}</p>
15
+ *
16
+ * <p>There are two possible options for server side encrption. This can be using a customer managed key or AWS managed CMK.</p>
17
+ *
18
+ * Example usage:
19
+ *
20
+ * <pre>
21
+ * withServerSideEncryption(ServerSideEncrptionFactory.awsManagedCmk())
22
+ * </pre>
23
+ *
24
+ * or
25
+ *
26
+ * <pre>
27
+ * withServerSideEncryption(ServerSideEncrptionFactory.customerKey(YOUR_CUSTOMER_ID))
28
+ * </pre>
29
+ *
30
+ * @see software.amazon.payloadoffloading.ServerSideEncryptionFactory
13
31
*/
14
32
@ NotThreadSafe
15
33
public class PayloadStorageConfiguration {
16
- private static final Log LOG = LogFactory . getLog (PayloadStorageConfiguration .class );
34
+ private static final Logger LOG = LoggerFactory . getLogger (PayloadStorageConfiguration .class );
17
35
18
- private AmazonS3 s3 ;
36
+ private S3Client s3 ;
19
37
private String s3BucketName ;
20
38
private int payloadSizeThreshold = 0 ;
21
39
private boolean alwaysThroughS3 = false ;
22
40
private boolean payloadSupport = false ;
23
41
/**
24
42
* This field is optional, it is set only when we want to configure S3 Server Side Encryption with KMS.
25
43
*/
26
- private SSEAwsKeyManagementParams sseAwsKeyManagementParams ;
44
+ private ServerSideEncryptionStrategy serverSideEncryptionStrategy ;
27
45
28
46
public PayloadStorageConfiguration () {
29
47
s3 = null ;
30
48
s3BucketName = null ;
31
- sseAwsKeyManagementParams = null ;
49
+ serverSideEncryptionStrategy = null ;
32
50
}
33
51
34
52
public PayloadStorageConfiguration (PayloadStorageConfiguration other ) {
35
- this .s3 = other .getAmazonS3Client ();
53
+ this .s3 = other .getS3Client ();
36
54
this .s3BucketName = other .getS3BucketName ();
37
- this .sseAwsKeyManagementParams = other .getSSEAwsKeyManagementParams ();
38
55
this .payloadSupport = other .isPayloadSupportEnabled ();
39
56
this .alwaysThroughS3 = other .isAlwaysThroughS3 ();
40
57
this .payloadSizeThreshold = other .getPayloadSizeThreshold ();
58
+ this .serverSideEncryptionStrategy = other .getServerSideEncryptionStrategy ();
41
59
}
42
60
43
61
/**
@@ -47,11 +65,11 @@ public PayloadStorageConfiguration(PayloadStorageConfiguration other) {
47
65
* @param s3BucketName Name of the bucket which is going to be used for storing payload.
48
66
* The bucket must be already created and configured in s3.
49
67
*/
50
- public void setPayloadSupportEnabled (AmazonS3 s3 , String s3BucketName ) {
68
+ public void setPayloadSupportEnabled (S3Client s3 , String s3BucketName ) {
51
69
if (s3 == null || s3BucketName == null ) {
52
70
String errorMessage = "S3 client and/or S3 bucket name cannot be null." ;
53
71
LOG .error (errorMessage );
54
- throw new AmazonClientException (errorMessage );
72
+ throw SdkClientException . create (errorMessage );
55
73
}
56
74
if (isPayloadSupportEnabled ()) {
57
75
LOG .warn ("Payload support is already enabled. Overwriting AmazonS3Client and S3BucketName." );
@@ -70,7 +88,7 @@ public void setPayloadSupportEnabled(AmazonS3 s3, String s3BucketName) {
70
88
* The bucket must be already created and configured in s3.
71
89
* @return the updated PayloadStorageConfiguration object.
72
90
*/
73
- public PayloadStorageConfiguration withPayloadSupportEnabled (AmazonS3 s3 , String s3BucketName ) {
91
+ public PayloadStorageConfiguration withPayloadSupportEnabled (S3Client s3 , String s3BucketName ) {
74
92
setPayloadSupportEnabled (s3 , s3BucketName );
75
93
return this ;
76
94
}
@@ -109,7 +127,7 @@ public boolean isPayloadSupportEnabled() {
109
127
*
110
128
* @return Reference to the Amazon S3 client which is being used.
111
129
*/
112
- public AmazonS3 getAmazonS3Client () {
130
+ public S3Client getS3Client () {
113
131
return s3 ;
114
132
}
115
133
@@ -122,35 +140,6 @@ public String getS3BucketName() {
122
140
return s3BucketName ;
123
141
}
124
142
125
- /**
126
- * Gets the S3 SSE-KMS encryption params of S3 objects under configured S3 bucket name.
127
- *
128
- * @return The S3 SSE-KMS params used for encryption.
129
- */
130
- public SSEAwsKeyManagementParams getSSEAwsKeyManagementParams () {
131
- return sseAwsKeyManagementParams ;
132
- }
133
-
134
- /**
135
- * Sets the the S3 SSE-KMS encryption params of S3 objects under configured S3 bucket name.
136
- *
137
- * @param sseAwsKeyManagementParams The S3 SSE-KMS params used for encryption.
138
- */
139
- public void setSSEAwsKeyManagementParams (SSEAwsKeyManagementParams sseAwsKeyManagementParams ) {
140
- this .sseAwsKeyManagementParams = sseAwsKeyManagementParams ;
141
- }
142
-
143
- /**
144
- * Sets the the S3 SSE-KMS encryption params of S3 objects under configured S3 bucket name.
145
- *
146
- * @param sseAwsKeyManagementParams The S3 SSE-KMS params used for encryption.
147
- * @return the updated PayloadStorageConfiguration object
148
- */
149
- public PayloadStorageConfiguration withSSEAwsKeyManagementParams (SSEAwsKeyManagementParams sseAwsKeyManagementParams ) {
150
- setSSEAwsKeyManagementParams (sseAwsKeyManagementParams );
151
- return this ;
152
- }
153
-
154
143
/**
155
144
* Sets the payload size threshold for storing payloads in Amazon S3.
156
145
*
@@ -212,4 +201,38 @@ public boolean isAlwaysThroughS3() {
212
201
public void setAlwaysThroughS3 (boolean alwaysThroughS3 ) {
213
202
this .alwaysThroughS3 = alwaysThroughS3 ;
214
203
}
204
+
205
+ /**
206
+ * Sets which method of server side encryption should be used, if required.
207
+ *
208
+ * This is optional, it is set only when you want to configure S3 server side encryption with KMS.
209
+ *
210
+ * @param serverSideEncryptionStrategy The method of encryption required for S3 server side encryption with KMS.
211
+ * @return the updated PayloadStorageConfiguration object.
212
+ */
213
+ public PayloadStorageConfiguration withServerSideEncryption (ServerSideEncryptionStrategy serverSideEncryptionStrategy ) {
214
+ setServerSideEncryptionStrategy (serverSideEncryptionStrategy );
215
+ return this ;
216
+ }
217
+
218
+ /**
219
+ * Sets which method of server side encryption should be use, if required.
220
+ *
221
+ * This is optional, it is set only when you want to configure S3 Server Side Encryption with KMS.
222
+ *
223
+ * @param serverSideEncryptionStrategy The method of encryption required for S3 server side encryption with KMS.
224
+ */
225
+ public void setServerSideEncryptionStrategy (ServerSideEncryptionStrategy serverSideEncryptionStrategy ) {
226
+ this .serverSideEncryptionStrategy = serverSideEncryptionStrategy ;
227
+ }
228
+
229
+ /**
230
+ * The method of service side encryption which should be used, if required.
231
+ *
232
+ * @return The server side encryption method required. Default null.
233
+ */
234
+ public ServerSideEncryptionStrategy getServerSideEncryptionStrategy () {
235
+ return this .serverSideEncryptionStrategy ;
236
+ }
237
+
215
238
}
0 commit comments