|
34 | 34 | import java.util.Map;
|
35 | 35 | import java.util.concurrent.CompletableFuture;
|
36 | 36 | import java.util.function.Consumer;
|
| 37 | +import java.util.function.Function; |
37 | 38 |
|
38 | 39 | public class S3AsyncEncryptionClient implements S3AsyncClient {
|
39 | 40 |
|
@@ -91,32 +92,26 @@ public CompletableFuture<DeleteObjectResponse> deleteObject(DeleteObjectRequest
|
91 | 92 | // TODO: Pass-through requests MUST set the user agent
|
92 | 93 | final CompletableFuture<DeleteObjectResponse> response = _wrappedClient.deleteObject(deleteObjectRequest);
|
93 | 94 | final String instructionObjectKey = deleteObjectRequest.key() + ".instruction";
|
94 |
| - // Deleting the instruction file is "fire and forget" |
95 |
| - // This is necessary because the encryption client must adhere to the |
96 |
| - // same interface as the default client thus it is not possible to |
97 |
| - // use e.g. allOf to return a future which includes both deletions. |
98 |
| - _wrappedClient.deleteObject(builder -> builder |
| 95 | + final CompletableFuture<DeleteObjectResponse> instructionResponse = _wrappedClient.deleteObject(builder -> builder |
99 | 96 | .bucket(deleteObjectRequest.bucket())
|
100 | 97 | .key(instructionObjectKey));
|
101 |
| - return response; |
| 98 | + // Delete the instruction file, then delete the object |
| 99 | + Function<DeleteObjectResponse, DeleteObjectResponse> deletion = deleteObjectResponse -> |
| 100 | + response.join(); |
| 101 | + return instructionResponse.thenApplyAsync(deletion); |
102 | 102 | }
|
103 | 103 |
|
104 | 104 | @Override
|
105 | 105 | public CompletableFuture<DeleteObjectsResponse> deleteObjects(DeleteObjectsRequest deleteObjectsRequest) throws AwsServiceException,
|
106 | 106 | SdkClientException {
|
107 | 107 | // TODO: Pass-through requests MUST set the user agent
|
108 |
| - final CompletableFuture<DeleteObjectsResponse> deleteObjectsResponse = _wrappedClient.deleteObjects(deleteObjectsRequest); |
109 |
| - // If Instruction files exists, delete the instruction files as well. |
110 |
| - final List<ObjectIdentifier> deleteObjects = S3EncryptionClientUtilities.instructionFileKeysToDelete(deleteObjectsRequest); |
111 |
| - // Deleting the instruction files is "fire and forget" |
112 |
| - // This is necessary because the encryption client must adhere to the |
113 |
| - // same interface as the default client thus it is not possible to |
114 |
| - // use e.g. allOf to return a future which includes both deletions. |
115 |
| - _wrappedClient.deleteObjects(DeleteObjectsRequest.builder() |
116 |
| - .bucket(deleteObjectsRequest.bucket()) |
117 |
| - .delete(builder -> builder.objects(deleteObjects)) |
| 108 | + // Add the instruction file keys to the list of objects to delete |
| 109 | + final List<ObjectIdentifier> objectsToDelete = S3EncryptionClientUtilities.instructionFileKeysToDelete(deleteObjectsRequest); |
| 110 | + // Add the original objects |
| 111 | + objectsToDelete.addAll(deleteObjectsRequest.delete().objects()); |
| 112 | + return _wrappedClient.deleteObjects(deleteObjectsRequest.toBuilder() |
| 113 | + .delete(builder -> builder.objects(objectsToDelete)) |
118 | 114 | .build());
|
119 |
| - return deleteObjectsResponse; |
120 | 115 | }
|
121 | 116 |
|
122 | 117 | @Override
|
|
0 commit comments