Skip to content

Commit

Permalink
storage: Fix rewrite operation to support predefinedAcl on a copy (#3467
Browse files Browse the repository at this point in the history
)
  • Loading branch information
frankyn authored and pongad committed Jul 13, 2018
1 parent af56b5b commit 445869c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,6 @@ private RewriteResponse rewrite(RewriteRequest req, String token) {
if (userProject == null) {
userProject = Option.USER_PROJECT.getString(req.targetOptions);
}
String kmsKeyName = Option.KMS_KEY_NAME.getString(req.targetOptions);

Long maxBytesRewrittenPerCall = req.megabytesRewrittenPerCall != null
? req.megabytesRewrittenPerCall * MEGABYTE : null;
Expand All @@ -812,8 +811,9 @@ private RewriteResponse rewrite(RewriteRequest req, String token) {
.setIfMetagenerationNotMatch(Option.IF_METAGENERATION_NOT_MATCH.getLong(req.targetOptions))
.setIfGenerationMatch(Option.IF_GENERATION_MATCH.getLong(req.targetOptions))
.setIfGenerationNotMatch(Option.IF_GENERATION_NOT_MATCH.getLong(req.targetOptions))
.setDestinationPredefinedAcl(Option.PREDEFINED_ACL.getString(req.targetOptions))
.setUserProject(userProject)
.setDestinationKmsKeyName(kmsKeyName);
.setDestinationKmsKeyName(Option.KMS_KEY_NAME.getString(req.targetOptions));
HttpHeaders requestHeaders = rewrite.getRequestHeaders();
setEncryptionHeaders(requestHeaders, SOURCE_ENCRYPTION_KEY_PREFIX, req.sourceOptions);
setEncryptionHeaders(requestHeaders, ENCRYPTION_KEY_PREFIX, req.targetOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,34 @@ public void testCopyBlob() {
assertTrue(storage.delete(BUCKET, targetBlobName));
}

@Test
public void testCopyBlobWithPredefinedAcl() {
String sourceBlobName = "test-copy-blob-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
ImmutableMap<String, String> metadata = ImmutableMap.of("k", "v");
BlobInfo blob = BlobInfo.newBuilder(source)
.setContentType(CONTENT_TYPE)
.setMetadata(metadata)
.build();
Blob remoteBlob = storage.create(blob, BLOB_BYTE_CONTENT);
assertNotNull(remoteBlob);
String targetBlobName = "test-copy-blob-target";
Storage.CopyRequest req = Storage.CopyRequest.newBuilder()
.setSource(source)
.setTarget(BlobId.of(BUCKET, targetBlobName),
Storage.BlobTargetOption.predefinedAcl(Storage.PredefinedAcl.PUBLIC_READ))
.build();
CopyWriter copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(CONTENT_TYPE, copyWriter.getResult().getContentType());
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertNotNull(copyWriter.getResult().getAcl(User.ofAllUsers()));
assertTrue(copyWriter.isDone());
assertTrue(remoteBlob.delete());
assertTrue(storage.delete(BUCKET, targetBlobName));
}

@Test
public void testCopyBlobWithEncryptionKeys() {
String sourceBlobName = "test-copy-blob-encryption-key-source";
Expand Down

0 comments on commit 445869c

Please sign in to comment.