Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion google-cloud-storage/pom.xml
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,7 @@
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-storage</artifactId>
<version>v1-rev100-1.22.0</version>
<version>v1-rev108-1.22.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,6 +40,7 @@
import java.security.Key;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

Expand DownExpand Up@@ -565,6 +566,12 @@ public Builder setDefaultAcl(Iterable<Acl> acl) {
return this;
}

@Override
public Builder setLabels(Map<String, String> labels) {
infoBuilder.setLabels(labels);
return this;
}

@Override
public Bucket build() {
return new Bucket(storage, infoBuilder);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,12 +34,14 @@
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
Expand DownExpand Up@@ -81,6 +83,7 @@ public com.google.api.services.storage.model.Bucket apply(BucketInfo bucketInfo)
private final List<Acl> defaultAcl;
private final String location;
private final StorageClass storageClass;
private final Map<String, String> labels;

/**
* Base class for bucket's delete rules. Allows to configure automatic deletion of blobs and blobs
Expand DownExpand Up@@ -406,6 +409,11 @@ public abstract static class Builder {
*/
public abstract Builder setDefaultAcl(Iterable<Acl> acl);

/**
* Sets the label of this bucket.
*/
public abstract Builder setLabels(Map<String, String> labels);

/**
* Creates a {@code BucketInfo} object.
*/
Expand All@@ -430,6 +438,7 @@ static final class BuilderImpl extends Builder {
private List<Cors> cors;
private List<Acl> acl;
private List<Acl> defaultAcl;
private Map<String, String> labels;

BuilderImpl(String name) {
this.name = name;
Expand All@@ -452,6 +461,7 @@ static final class BuilderImpl extends Builder {
indexPage = bucketInfo.indexPage;
notFoundPage = bucketInfo.notFoundPage;
deleteRules = bucketInfo.deleteRules;
labels = bucketInfo.labels;
}

@Override
Expand DownExpand Up@@ -550,6 +560,12 @@ public Builder setDefaultAcl(Iterable<Acl> acl) {
return this;
}

@Override
public Builder setLabels(Map<String, String> labels) {
this.labels = labels != null ? ImmutableMap.copyOf(labels) : null;
return this;
}

@Override
public BucketInfo build() {
checkNotNull(name);
Expand All@@ -574,6 +590,7 @@ public BucketInfo build() {
indexPage = builder.indexPage;
notFoundPage = builder.notFoundPage;
deleteRules = builder.deleteRules;
labels = builder.labels;
}

/**
Expand DownExpand Up@@ -708,6 +725,13 @@ public List<Acl> getDefaultAcl() {
return defaultAcl;
}

/**
* Returns the labels for this bucket.
*/
public Map<String, String> getLabels() {
return labels;
}

/**
* Returns a builder for the current bucket.
*/
Expand DownExpand Up@@ -795,6 +819,10 @@ public Rule apply(DeleteRule deleteRule) {
}));
bucketPb.setLifecycle(lifecycle);
}
if (labels != null) {
bucketPb.setLabels(labels);
}

return bucketPb;
}

Expand DownExpand Up@@ -875,6 +903,9 @@ public DeleteRule apply(Rule rule) {
}
}));
}
if (bucketPb.getLabels() != null) {
builder.setLabels(bucketPb.getLabels());
}
return builder.build();
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,10 +33,12 @@
import com.google.cloud.storage.BucketInfo.RawDeleteRule;
import com.google.common.collect.ImmutableList;

import com.google.common.collect.ImmutableMap;
import org.junit.Test;

import java.util.Collections;
import java.util.List;
import java.util.Map;

public class BucketInfoTest {

Expand All@@ -59,6 +61,7 @@ public class BucketInfoTest {
private static final String LOCATION = "ASIA";
private static final StorageClass STORAGE_CLASS = StorageClass.STANDARD;
private static final Boolean VERSIONING_ENABLED = true;
private static final Map<String, String> BUCKET_LABELS = ImmutableMap.of("label1", "value1");
private static final BucketInfo BUCKET_INFO = BucketInfo.newBuilder("b")
.setAcl(ACL)
.setEtag(ETAG)
Expand All@@ -75,6 +78,7 @@ public class BucketInfoTest {
.setLocation(LOCATION)
.setStorageClass(STORAGE_CLASS)
.setVersioningEnabled(VERSIONING_ENABLED)
.setLabels(BUCKET_LABELS)
.build();

@Test
Expand DownExpand Up@@ -117,6 +121,7 @@ public void testBuilder() {
assertEquals(LOCATION, BUCKET_INFO.getLocation());
assertEquals(STORAGE_CLASS, BUCKET_INFO.getStorageClass());
assertEquals(VERSIONING_ENABLED, BUCKET_INFO.versioningEnabled());
assertEquals(BUCKET_LABELS, BUCKET_INFO.getLabels());
}

@Test
Expand DownExpand Up@@ -144,6 +149,7 @@ private void compareBuckets(BucketInfo expected, BucketInfo value) {
assertEquals(expected.getLocation(), value.getLocation());
assertEquals(expected.getStorageClass(), value.getStorageClass());
assertEquals(expected.versioningEnabled(), value.versioningEnabled());
assertEquals(expected.getLabels(), value.getLabels());
}

@Test
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,7 @@
import com.google.cloud.storage.BucketInfo.DeleteRule;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.io.BaseEncoding;

Expand All@@ -52,6 +53,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.crypto.spec.SecretKeySpec;

Expand All@@ -76,6 +78,8 @@ public class BucketTest {
private static final String LOCATION = "ASIA";
private static final StorageClass STORAGE_CLASS = StorageClass.STANDARD;
private static final Boolean VERSIONING_ENABLED = true;
private static final Map<String, String> BUCKET_LABELS = ImmutableMap.of("label1", "value1");

private static final BucketInfo FULL_BUCKET_INFO = BucketInfo.newBuilder("b")
.setAcl(ACLS)
.setEtag(ETAG)
Expand All@@ -92,6 +96,7 @@ public class BucketTest {
.setLocation(LOCATION)
.setStorageClass(STORAGE_CLASS)
.setVersioningEnabled(VERSIONING_ENABLED)
.setLabels(BUCKET_LABELS)
.build();
private static final BucketInfo BUCKET_INFO =
BucketInfo.newBuilder("b").setMetageneration(42L).build();
Expand DownExpand Up@@ -662,6 +667,7 @@ public void testBuilder() {
.setLocation(LOCATION)
.setStorageClass(STORAGE_CLASS)
.setVersioningEnabled(VERSIONING_ENABLED)
.setLabels(BUCKET_LABELS)
.build();
assertEquals("b", bucket.getName());
assertEquals(ACLS, bucket.getAcl());
Expand All@@ -679,6 +685,7 @@ public void testBuilder() {
assertEquals(LOCATION, bucket.getLocation());
assertEquals(STORAGE_CLASS, bucket.getStorageClass());
assertEquals(VERSIONING_ENABLED, bucket.versioningEnabled());
assertEquals(BUCKET_LABELS, bucket.getLabels());
assertEquals(storage.getOptions(), bucket.getStorage().getOptions());
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,6 +103,7 @@ public class ITStorageTest {
new SecretKeySpec(BaseEncoding.base64().decode(BASE64_KEY), "AES256");
private static final byte[] COMPRESSED_CONTENT = BaseEncoding.base64()
.decode("H4sIAAAAAAAAAPNIzcnJV3DPz0/PSVVwzskvTVEILskvSkxPVQQA/LySchsAAAA=");
private static final Map<String, String> BUCKET_LABELS = ImmutableMap.of("label1", "value1");

@BeforeClass
public static void beforeClass() throws NoSuchAlgorithmException, InvalidKeySpecException {
Expand DownExpand Up@@ -1489,4 +1490,13 @@ public void testBucketPolicy() {
BUCKET,
ImmutableList.of("storage.buckets.getIamPolicy", "storage.buckets.setIamPolicy")));
}

@Test
public void testUpdateBucketLabel() {
Bucket remoteBucket = storage.get(BUCKET, Storage.BucketGetOption.fields(BucketField.ID));
assertNull(remoteBucket.getLabels());
remoteBucket = remoteBucket.toBuilder().setLabels(BUCKET_LABELS).build();
Bucket updatedBucket = storage.update(remoteBucket);
assertEquals(BUCKET_LABELS, updatedBucket.getLabels());
}
}