11package software .amazon .payloadoffloading ;
22
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 ;
98
109/**
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
1331 */
1432@ NotThreadSafe
1533public class PayloadStorageConfiguration {
16- private static final Log LOG = LogFactory . getLog (PayloadStorageConfiguration .class );
34+ private static final Logger LOG = LoggerFactory . getLogger (PayloadStorageConfiguration .class );
1735
18- private AmazonS3 s3 ;
36+ private S3Client s3 ;
1937 private String s3BucketName ;
2038 private int payloadSizeThreshold = 0 ;
2139 private boolean alwaysThroughS3 = false ;
2240 private boolean payloadSupport = false ;
2341 /**
2442 * This field is optional, it is set only when we want to configure S3 Server Side Encryption with KMS.
2543 */
26- private SSEAwsKeyManagementParams sseAwsKeyManagementParams ;
44+ private ServerSideEncryptionStrategy serverSideEncryptionStrategy ;
2745
2846 public PayloadStorageConfiguration () {
2947 s3 = null ;
3048 s3BucketName = null ;
31- sseAwsKeyManagementParams = null ;
49+ serverSideEncryptionStrategy = null ;
3250 }
3351
3452 public PayloadStorageConfiguration (PayloadStorageConfiguration other ) {
35- this .s3 = other .getAmazonS3Client ();
53+ this .s3 = other .getS3Client ();
3654 this .s3BucketName = other .getS3BucketName ();
37- this .sseAwsKeyManagementParams = other .getSSEAwsKeyManagementParams ();
3855 this .payloadSupport = other .isPayloadSupportEnabled ();
3956 this .alwaysThroughS3 = other .isAlwaysThroughS3 ();
4057 this .payloadSizeThreshold = other .getPayloadSizeThreshold ();
58+ this .serverSideEncryptionStrategy = other .getServerSideEncryptionStrategy ();
4159 }
4260
4361 /**
@@ -47,11 +65,11 @@ public PayloadStorageConfiguration(PayloadStorageConfiguration other) {
4765 * @param s3BucketName Name of the bucket which is going to be used for storing payload.
4866 * The bucket must be already created and configured in s3.
4967 */
50- public void setPayloadSupportEnabled (AmazonS3 s3 , String s3BucketName ) {
68+ public void setPayloadSupportEnabled (S3Client s3 , String s3BucketName ) {
5169 if (s3 == null || s3BucketName == null ) {
5270 String errorMessage = "S3 client and/or S3 bucket name cannot be null." ;
5371 LOG .error (errorMessage );
54- throw new AmazonClientException (errorMessage );
72+ throw SdkClientException . create (errorMessage );
5573 }
5674 if (isPayloadSupportEnabled ()) {
5775 LOG .warn ("Payload support is already enabled. Overwriting AmazonS3Client and S3BucketName." );
@@ -70,7 +88,7 @@ public void setPayloadSupportEnabled(AmazonS3 s3, String s3BucketName) {
7088 * The bucket must be already created and configured in s3.
7189 * @return the updated PayloadStorageConfiguration object.
7290 */
73- public PayloadStorageConfiguration withPayloadSupportEnabled (AmazonS3 s3 , String s3BucketName ) {
91+ public PayloadStorageConfiguration withPayloadSupportEnabled (S3Client s3 , String s3BucketName ) {
7492 setPayloadSupportEnabled (s3 , s3BucketName );
7593 return this ;
7694 }
@@ -109,7 +127,7 @@ public boolean isPayloadSupportEnabled() {
109127 *
110128 * @return Reference to the Amazon S3 client which is being used.
111129 */
112- public AmazonS3 getAmazonS3Client () {
130+ public S3Client getS3Client () {
113131 return s3 ;
114132 }
115133
@@ -122,35 +140,6 @@ public String getS3BucketName() {
122140 return s3BucketName ;
123141 }
124142
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-
154143 /**
155144 * Sets the payload size threshold for storing payloads in Amazon S3.
156145 *
@@ -212,4 +201,38 @@ public boolean isAlwaysThroughS3() {
212201 public void setAlwaysThroughS3 (boolean alwaysThroughS3 ) {
213202 this .alwaysThroughS3 = alwaysThroughS3 ;
214203 }
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+
215238}
0 commit comments