Skip to content
Snippets Groups Projects
Commit 98564925 authored by ivan's avatar ivan
Browse files

[s3] added support for SSE

parent 07c06cfb
No related branches found
No related tags found
No related merge requests found
...@@ -13,3 +13,6 @@ s3.secretKey=YourSecret ...@@ -13,3 +13,6 @@ s3.secretKey=YourSecret
# the AWS endpoint # the AWS endpoint
s3.endpoint=s3.amazonaws.com s3.endpoint=s3.amazonaws.com
# activating the SSE server side encryption if true
s3.sse=false
...@@ -70,6 +70,7 @@ import com.amazonaws.services.s3.model.S3ObjectSummary; ...@@ -70,6 +70,7 @@ import com.amazonaws.services.s3.model.S3ObjectSummary;
public class S3Client extends DB { public class S3Client extends DB {
private static AmazonS3Client s3Client; private static AmazonS3Client s3Client;
private static String sse;
private static final AtomicInteger INIT_COUNT = new AtomicInteger(0); private static final AtomicInteger INIT_COUNT = new AtomicInteger(0);
//private static int initCount = 0; //private static int initCount = 0;
...@@ -178,7 +179,10 @@ public class S3Client extends DB { ...@@ -178,7 +179,10 @@ public class S3Client extends DB {
if (maxErrorRetry == null){ if (maxErrorRetry == null){
maxErrorRetry = propsCL.getProperty("s3.maxErrorRetry", "15"); maxErrorRetry = propsCL.getProperty("s3.maxErrorRetry", "15");
} }
System.out.println(maxErrorRetry); sse = props.getProperty("s3.sse");
if (sse == null){
sse = propsCL.getProperty("s3.sse", "false");
}
} catch (Exception e){ } catch (Exception e){
System.err.println("The file properties doesn't exist "+e.toString()); System.err.println("The file properties doesn't exist "+e.toString());
e.printStackTrace(); e.printStackTrace();
...@@ -226,7 +230,7 @@ public class S3Client extends DB { ...@@ -226,7 +230,7 @@ public class S3Client extends DB {
@Override @Override
public int insert(String bucket, String key, public int insert(String bucket, String key,
HashMap<String, ByteIterator> values) { HashMap<String, ByteIterator> values) {
return writeToStorage(bucket, key, values, true); return writeToStorage(bucket, key, values, true, sse);
} }
/** /**
* Read a file from the Bucket. Each field/value pair from the result * Read a file from the Bucket. Each field/value pair from the result
...@@ -265,7 +269,7 @@ public class S3Client extends DB { ...@@ -265,7 +269,7 @@ public class S3Client extends DB {
@Override @Override
public int update(String bucket, String key, public int update(String bucket, String key,
HashMap<String, ByteIterator> values) { HashMap<String, ByteIterator> values) {
return writeToStorage(bucket, key, values, false); return writeToStorage(bucket, key, values, false, sse);
} }
/** /**
* Perform a range scan for a set of files in the bucket. Each * Perform a range scan for a set of files in the bucket. Each
...@@ -305,7 +309,8 @@ public class S3Client extends DB { ...@@ -305,7 +309,8 @@ public class S3Client extends DB {
* *
*/ */
protected int writeToStorage(String bucket, String key, protected int writeToStorage(String bucket, String key,
HashMap<String, ByteIterator> values, Boolean updateMarker) { HashMap<String, ByteIterator> values, Boolean updateMarker,
String sseLocal) {
int totalSize = 0; int totalSize = 0;
int fieldCount = values.size(); //number of fields to concatenate int fieldCount = values.size(); //number of fields to concatenate
// getting the first field in the values // getting the first field in the values
...@@ -338,12 +343,20 @@ public class S3Client extends DB { ...@@ -338,12 +343,20 @@ public class S3Client extends DB {
} }
try (InputStream input = new ByteArrayInputStream(destinationArray)) { try (InputStream input = new ByteArrayInputStream(destinationArray)) {
ObjectMetadata metadata = new ObjectMetadata(); ObjectMetadata metadata = new ObjectMetadata();
if (sseLocal.equals("true")) {
metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
}
metadata.setContentLength(totalSize); metadata.setContentLength(totalSize);
try { try {
PutObjectResult res = PutObjectResult res =
s3Client.putObject(bucket, key, input, metadata); s3Client.putObject(bucket, key, input, metadata);
if(res.getETag() == null) { if(res.getETag() == null) {
return 1; return 1;
} else {
if (sseLocal.equals("true")) {
System.out.println("Uploaded object encryption status is " +
res.getSSEAlgorithm());
}
} }
} catch (Exception e) { } catch (Exception e) {
System.err.println("Not possible to write object :"+key); System.err.println("Not possible to write object :"+key);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment