Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: use defaul service account creadential and add testcase for del…
…ete lifecycle rules
  • Loading branch information
athakor committed May 18, 2020
commit 08e5c39c24e93de83b6610e169542ab217a8515a
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,9 @@ public boolean deleteDefaultAcl(Entity entity) {
*
* @return {@code true} if the bucket lifecycle rules were deleted.
* @throws StorageException upon failure
* @throws IOException
*/
public boolean deleteLifecycleRules() {
public boolean deleteLifecycleRules() throws IOException {
return storage.deleteLifecycleRules(getName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.io.BaseEncoding;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.net.URL;
Expand Down Expand Up @@ -3102,8 +3103,9 @@ PostPolicyV4 generateSignedPostPolicyV4(
* @param bucket name of the bucket.
* @return {@code true} if the bucket lifecycle rules were deleted.
* @throws StorageException upon failure
* @throws IOException
*/
boolean deleteLifecycleRules(String bucket);
boolean deleteLifecycleRules(String bucket) throws IOException;

/**
* Creates a new default blob ACL entry on the specified bucket.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
import com.google.api.services.storage.model.StorageObject;
import com.google.api.services.storage.model.TestIamPermissionsResponse;
import com.google.auth.ServiceAccountSigner;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.BaseService;
import com.google.cloud.BatchResult;
import com.google.cloud.PageImpl;
import com.google.cloud.PageImpl.NextPageFetcher;
import com.google.cloud.Policy;
import com.google.cloud.ReadChannel;
import com.google.cloud.RetryHelper.RetryHelperException;
import com.google.cloud.ServiceOptions;
import com.google.cloud.Tuple;
import com.google.cloud.storage.Acl.Entity;
import com.google.cloud.storage.HmacKey.HmacKeyMetadata;
Expand All @@ -71,6 +71,7 @@
import com.google.common.io.BaseEncoding;
import com.google.common.primitives.Ints;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -1160,16 +1161,16 @@ public Boolean call() {
}

@Override
public boolean deleteLifecycleRules(final String bucket) {
public boolean deleteLifecycleRules(final String bucket) throws IOException {
final com.google.api.services.storage.model.Bucket bucketPb = BucketInfo.of(bucket).toPb();
final com.google.api.services.storage.model.ServiceAccount serviceAccount =
storageRpc.getServiceAccount(ServiceOptions.getDefaultProjectId());
final ServiceAccountCredentials serviceAccount =
(ServiceAccountCredentials) ServiceAccountCredentials.getApplicationDefault();
try {
return runWithRetries(
new Callable<Boolean>() {
@Override
public Boolean call() {
return storageRpc.deleteLifecycleRules(bucketPb, serviceAccount.getEmailAddress());
return storageRpc.deleteLifecycleRules(bucketPb, serviceAccount.getClientEmail());
}
},
getOptions().getRetrySettings(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.cloud.ServiceRpc;
import com.google.cloud.Tuple;
import com.google.cloud.storage.StorageException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
Expand Down Expand Up @@ -261,6 +262,7 @@ public int hashCode() {
*
* @return {@code true} if the bucket lifecycle rules were deleted.
* @throws StorageException upon failure
* @throws IOException
*/
boolean deleteLifecycleRules(Bucket bucket, String serviceAccount);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.google.common.collect.Lists;
import com.google.common.io.BaseEncoding;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.Key;
import java.util.Collections;
Expand Down Expand Up @@ -704,7 +705,7 @@ public void testDeleteDefaultAcl() throws Exception {
}

@Test
public void testDeleteLifecycleRules() {
public void testDeleteLifecycleRules() throws IOException {
expect(storage.getOptions()).andReturn(mockOptions).times(1);
expect(storage.deleteLifecycleRules(BUCKET_INFO.getName())).andReturn(true);
replay(storage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2737,6 +2737,23 @@ public void testDeleteDefaultBucketAcl() {
assertTrue(storage.deleteDefaultAcl(BUCKET_NAME1, User.ofAllAuthenticatedUsers()));
}

@Test
public void testDeleteLifecyclesRulesOfBucket() throws IOException {
ServiceAccountCredentials credentials =
ServiceAccountCredentials.newBuilder()
.setClientEmail(SERVICE_ACCOUNT.getEmail())
.setPrivateKey(privateKey)
.build();
EasyMock.expect(
storageRpcMock.deleteLifecycleRules(
EasyMock.isA(com.google.api.services.storage.model.Bucket.class),
EasyMock.isA(String.class)))
.andReturn(true);
EasyMock.replay(storageRpcMock);
storage = options.toBuilder().setCredentials(credentials).build().getService();
assertTrue(storage.deleteLifecycleRules(BUCKET_NAME1));
}

@Test
public void testCreateDefaultBucketAcl() {
Acl returnedAcl = ACL.toBuilder().setEtag("ETAG").setId("ID").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3222,7 +3222,6 @@ public void testBucketLogging() throws ExecutionException, InterruptedException
}

@Test
<<<<<<< HEAD
public void testSignedPostPolicyV4() throws Exception {
PostFieldsV4 fields = PostFieldsV4.newBuilder().setAcl("public-read").build();

Expand Down Expand Up @@ -3277,7 +3276,8 @@ public void testBlobReload() throws Exception {
}

@Test
public void testDeleteLifecycleRules() throws ExecutionException, InterruptedException {
public void testDeleteLifecycleRules()
throws ExecutionException, InterruptedException, IOException {
String lifeCycleRuleBucket = RemoteStorageHelper.generateBucketName();
List<LifecycleRule> lifecycleRules =
ImmutableList.of(
Expand Down