-
Notifications
You must be signed in to change notification settings - Fork 15
V2 #6
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
Merged
Merged
V2 #6
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9ab197e
Porting the code to make use of the AWS SDK for Java 2.0.
msailes bf3bae8
Added the ServerSideEncryptionStrategy interface to handle the use ca…
msailes 326769c
Pull request feedback.
msailes 8b529b2
Updated to keep both v1 and v2 in the README.md
msailes 326631b
Fixing a typo
msailes a73e3c8
Fixing a typo.
msailes a671fce
Adding Unit Tests.
msailes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/software/amazon/payloadoffloading/AwsManagedCmk.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package software.amazon.payloadoffloading; | ||
|
||
import software.amazon.awssdk.services.s3.model.PutObjectRequest; | ||
import software.amazon.awssdk.services.s3.model.ServerSideEncryption; | ||
|
||
public class AwsManagedCmk implements ServerSideEncryptionStrategy { | ||
@Override | ||
public void decorate(PutObjectRequest.Builder putObjectRequestBuilder) { | ||
putObjectRequestBuilder.serverSideEncryption(ServerSideEncryption.AWS_KMS); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/software/amazon/payloadoffloading/CustomerKey.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package software.amazon.payloadoffloading; | ||
|
||
import software.amazon.awssdk.services.s3.model.PutObjectRequest; | ||
import software.amazon.awssdk.services.s3.model.ServerSideEncryption; | ||
|
||
public class CustomerKey implements ServerSideEncryptionStrategy { | ||
private final String awsKmsKeyId; | ||
|
||
public CustomerKey(String awsKmsKeyId) { | ||
this.awsKmsKeyId = awsKmsKeyId; | ||
} | ||
|
||
@Override | ||
public void decorate(PutObjectRequest.Builder putObjectRequestBuilder) { | ||
putObjectRequestBuilder.serverSideEncryption(ServerSideEncryption.AWS_KMS); | ||
putObjectRequestBuilder.ssekmsKeyId(awsKmsKeyId); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,61 @@ | ||
package software.amazon.payloadoffloading; | ||
|
||
import com.amazonaws.AmazonClientException; | ||
import com.amazonaws.annotation.NotThreadSafe; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.model.SSEAwsKeyManagementParams; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import software.amazon.awssdk.annotations.NotThreadSafe; | ||
import software.amazon.awssdk.core.exception.SdkClientException; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
|
||
/** | ||
* Amazon payload storage configuration options such as Amazon S3 client, | ||
* bucket name, and payload size threshold for payloads. | ||
* <p>Amazon payload storage configuration options such as Amazon S3 client, | ||
* bucket name, and payload size threshold for payloads.</p> | ||
* | ||
* <p>Server side encryption is optional and can be enabled using with {@link #withServerSideEncryption(ServerSideEncryptionStrategy)} | ||
* or {@link #setServerSideEncryptionStrategy(ServerSideEncryptionStrategy)}</p> | ||
* | ||
* <p>There are two possible options for server side encrption. This can be using a customer managed key or AWS managed CMK.</p> | ||
* | ||
* Example usage: | ||
* | ||
* <pre> | ||
* withServerSideEncryption(ServerSideEncrptionFactory.awsManagedCmk()) | ||
* </pre> | ||
* | ||
* or | ||
* | ||
* <pre> | ||
* withServerSideEncryption(ServerSideEncrptionFactory.customerKey(YOUR_CUSTOMER_ID)) | ||
* </pre> | ||
* | ||
* @see software.amazon.payloadoffloading.ServerSideEncryptionFactory | ||
*/ | ||
@NotThreadSafe | ||
public class PayloadStorageConfiguration { | ||
private static final Log LOG = LogFactory.getLog(PayloadStorageConfiguration.class); | ||
private static final Logger LOG = LoggerFactory.getLogger(PayloadStorageConfiguration.class); | ||
|
||
private AmazonS3 s3; | ||
private S3Client s3; | ||
private String s3BucketName; | ||
private int payloadSizeThreshold = 0; | ||
private boolean alwaysThroughS3 = false; | ||
private boolean payloadSupport = false; | ||
/** | ||
* This field is optional, it is set only when we want to configure S3 Server Side Encryption with KMS. | ||
*/ | ||
private SSEAwsKeyManagementParams sseAwsKeyManagementParams; | ||
private ServerSideEncryptionStrategy serverSideEncryptionStrategy; | ||
|
||
public PayloadStorageConfiguration() { | ||
s3 = null; | ||
s3BucketName = null; | ||
sseAwsKeyManagementParams = null; | ||
serverSideEncryptionStrategy = null; | ||
} | ||
|
||
public PayloadStorageConfiguration(PayloadStorageConfiguration other) { | ||
this.s3 = other.getAmazonS3Client(); | ||
this.s3 = other.getS3Client(); | ||
this.s3BucketName = other.getS3BucketName(); | ||
this.sseAwsKeyManagementParams = other.getSSEAwsKeyManagementParams(); | ||
this.payloadSupport = other.isPayloadSupportEnabled(); | ||
this.alwaysThroughS3 = other.isAlwaysThroughS3(); | ||
this.payloadSizeThreshold = other.getPayloadSizeThreshold(); | ||
this.serverSideEncryptionStrategy = other.getServerSideEncryptionStrategy(); | ||
} | ||
|
||
/** | ||
|
@@ -47,11 +65,11 @@ public PayloadStorageConfiguration(PayloadStorageConfiguration other) { | |
* @param s3BucketName Name of the bucket which is going to be used for storing payload. | ||
* The bucket must be already created and configured in s3. | ||
*/ | ||
public void setPayloadSupportEnabled(AmazonS3 s3, String s3BucketName) { | ||
public void setPayloadSupportEnabled(S3Client s3, String s3BucketName) { | ||
if (s3 == null || s3BucketName == null) { | ||
String errorMessage = "S3 client and/or S3 bucket name cannot be null."; | ||
LOG.error(errorMessage); | ||
throw new AmazonClientException(errorMessage); | ||
throw SdkClientException.create(errorMessage); | ||
} | ||
if (isPayloadSupportEnabled()) { | ||
LOG.warn("Payload support is already enabled. Overwriting AmazonS3Client and S3BucketName."); | ||
|
@@ -70,7 +88,7 @@ public void setPayloadSupportEnabled(AmazonS3 s3, String s3BucketName) { | |
* The bucket must be already created and configured in s3. | ||
* @return the updated PayloadStorageConfiguration object. | ||
*/ | ||
public PayloadStorageConfiguration withPayloadSupportEnabled(AmazonS3 s3, String s3BucketName) { | ||
public PayloadStorageConfiguration withPayloadSupportEnabled(S3Client s3, String s3BucketName) { | ||
setPayloadSupportEnabled(s3, s3BucketName); | ||
return this; | ||
} | ||
|
@@ -109,7 +127,7 @@ public boolean isPayloadSupportEnabled() { | |
* | ||
* @return Reference to the Amazon S3 client which is being used. | ||
*/ | ||
public AmazonS3 getAmazonS3Client() { | ||
public S3Client getS3Client() { | ||
return s3; | ||
} | ||
|
||
|
@@ -122,35 +140,6 @@ public String getS3BucketName() { | |
return s3BucketName; | ||
} | ||
|
||
/** | ||
* Gets the S3 SSE-KMS encryption params of S3 objects under configured S3 bucket name. | ||
* | ||
* @return The S3 SSE-KMS params used for encryption. | ||
*/ | ||
public SSEAwsKeyManagementParams getSSEAwsKeyManagementParams() { | ||
return sseAwsKeyManagementParams; | ||
} | ||
|
||
/** | ||
* Sets the the S3 SSE-KMS encryption params of S3 objects under configured S3 bucket name. | ||
* | ||
* @param sseAwsKeyManagementParams The S3 SSE-KMS params used for encryption. | ||
*/ | ||
public void setSSEAwsKeyManagementParams(SSEAwsKeyManagementParams sseAwsKeyManagementParams) { | ||
this.sseAwsKeyManagementParams = sseAwsKeyManagementParams; | ||
} | ||
|
||
/** | ||
* Sets the the S3 SSE-KMS encryption params of S3 objects under configured S3 bucket name. | ||
* | ||
* @param sseAwsKeyManagementParams The S3 SSE-KMS params used for encryption. | ||
* @return the updated PayloadStorageConfiguration object | ||
*/ | ||
public PayloadStorageConfiguration withSSEAwsKeyManagementParams(SSEAwsKeyManagementParams sseAwsKeyManagementParams) { | ||
setSSEAwsKeyManagementParams(sseAwsKeyManagementParams); | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the payload size threshold for storing payloads in Amazon S3. | ||
* | ||
|
@@ -212,4 +201,38 @@ public boolean isAlwaysThroughS3() { | |
public void setAlwaysThroughS3(boolean alwaysThroughS3) { | ||
this.alwaysThroughS3 = alwaysThroughS3; | ||
} | ||
|
||
/** | ||
* Sets which method of server side encryption should be used, if required. | ||
* | ||
* This is optional, it is set only when you want to configure S3 server side encryption with KMS. | ||
* | ||
* @param serverSideEncryptionStrategy The method of encryption required for S3 server side encryption with KMS. | ||
* @return | ||
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. Can we complete the 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. done |
||
*/ | ||
public PayloadStorageConfiguration withServerSideEncryption(ServerSideEncryptionStrategy serverSideEncryptionStrategy) { | ||
setServerSideEncryptionStrategy(serverSideEncryptionStrategy); | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets which method of server side encryption should be use, if required. | ||
* | ||
* This is optional, it is set only when you want to configure S3 Server Side Encryption with KMS. | ||
* | ||
* @param serverSideEncryptionStrategy The method of encryption required for S3 server side encryption with KMS. | ||
*/ | ||
public void setServerSideEncryptionStrategy(ServerSideEncryptionStrategy serverSideEncryptionStrategy) { | ||
this.serverSideEncryptionStrategy = serverSideEncryptionStrategy; | ||
} | ||
|
||
/** | ||
* The method of service side encryption which should be used, if required. | ||
* | ||
* @return The server side encryption method required. Default null. | ||
*/ | ||
public ServerSideEncryptionStrategy getServerSideEncryptionStrategy() { | ||
return this.serverSideEncryptionStrategy; | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.