Skip to content

Commit

Permalink
fix: rearrange, cleanup, deprecation and fixes in ServerSideEncryption
Browse files Browse the repository at this point in the history
1. Cleanup formatting issues.
2. Arrange code usage together.
3. Deprecate `getType()` and `marshal()`, `ServerSideEncryptionCopyWithCustomerKey` and
   `copyWithCustomerKey()`. Use `type()`, `headers()`, `copySourceHeaders()` and `withCustomerKey()`.
  • Loading branch information
balamurugana committed Jul 18, 2019
1 parent 4bbd323 commit f19ef50
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 166 deletions.
31 changes: 12 additions & 19 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ private void checkReadRequestSse(ServerSideEncryption sse) throws InvalidArgumen
return;
}

if (sse.getType() != ServerSideEncryption.Type.SSE_C) {
if (sse.type() != ServerSideEncryption.Type.SSE_C) {
throw new InvalidArgumentException("only SSE_C is supported for all read requests.");
}

Expand All @@ -1305,8 +1305,8 @@ private void checkWriteRequestSse(ServerSideEncryption sse) throws InvalidArgume
return;
}

if (sse.getType().requiresTls() && !this.baseUrl.isHttps()) {
throw new InvalidArgumentException(sse.getType().name()
if (sse.type().requiresTls() && !this.baseUrl.isHttps()) {
throw new InvalidArgumentException(sse.type().name()
+ " operations must be performed over a secure connection.");
}
}
Expand Down Expand Up @@ -1546,8 +1546,7 @@ public ObjectStat statObject(String bucketName, String objectName, ServerSideEnc

Map<String, String> headers = null;
if (sse != null) {
headers = new HashMap<>();
sse.marshal(headers);
headers = sse.headers();
}

HttpResponse response = executeHead(bucketName, objectName, headers);
Expand Down Expand Up @@ -1838,7 +1837,7 @@ public InputStream getObject(String bucketName, String objectName, Long offset,
}

if (sse != null) {
sse.marshal(headerMap);
headerMap.putAll(sse.headers());
}

HttpResponse response = executeGet(bucketName, objectName, headerMap, null);
Expand Down Expand Up @@ -2369,11 +2368,11 @@ public void copyObject(String bucketName, String objectName, Map<String,String>
headerMap.put("x-amz-copy-source", S3Escaper.encodePath(srcBucketName + "/" + srcObjectName));

if (sse != null) {
sse.marshal(headerMap);
headerMap.putAll(sse.headers());
}

if (srcSse != null) {
srcSse.marshal(headerMap);
headerMap.putAll(srcSse.copySourceHeaders());
}

if (copyConditions != null) {
Expand Down Expand Up @@ -4364,8 +4363,7 @@ private void putObject(String bucketName, String objectName, Long size, Object d

if (sse != null) {
checkWriteRequestSse(sse);
// The correct approach is see.marshal() needs to accept boolean isHttps and do above checks inside.
sse.marshal(headerMap);
headerMap.putAll(sse.headers());
}


Expand All @@ -4381,11 +4379,6 @@ private void putObject(String bucketName, String objectName, Long size, Object d
int lastPartSize = rv[2];
Part[] totalParts = new Part[partCount];

// if sse is requested set the necessary headers before we begin the multipart session.
if (sse != null) {
sse.marshal(headerMap);
}

// initiate new multipart upload.
String uploadId = initMultipartUpload(bucketName, objectName, headerMap);

Expand Down Expand Up @@ -4413,10 +4406,10 @@ private void putObject(String bucketName, String objectName, Long size, Object d
}
}

// In multi-part uploads, Set encryption headers in the case of SSE-C.
Map<String, String> encryptionHeaders = new HashMap<>();
if (sse != null && sse.getType() == ServerSideEncryption.Type.SSE_C) {
sse.marshal(encryptionHeaders);
Map<String, String> encryptionHeaders = null;
// In multi-part uploads, set encryption headers in the case of SSE-C.
if (sse != null && sse.type() == ServerSideEncryption.Type.SSE_C) {
encryptionHeaders = sse.headers();
}

String etag = putObject(bucketName, objectName, data, expectedReadSize, encryptionHeaders,
Expand Down
Loading

0 comments on commit f19ef50

Please sign in to comment.