Skip to content

Commit 973639a

Browse files
committed
Add Acl.of method to storage module
1 parent 0c3e935 commit 973639a

5 files changed

Lines changed: 25 additions & 21 deletions

File tree

gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,7 @@ String toPb() {
274274
}
275275
}
276276

277-
/**
278-
* Creates an ACL object.
279-
*
280-
* @param entity the entity for this ACL object
281-
* @param role the role to associate to the {@code entity} object
282-
*/
283-
public Acl(Entity entity, Role role) {
277+
private Acl(Entity entity, Role role) {
284278
this.entity = entity;
285279
this.role = role;
286280
}
@@ -299,6 +293,16 @@ public Role role() {
299293
return role;
300294
}
301295

296+
/**
297+
* Returns an Acl object.
298+
*
299+
* @param entity the entity for this ACL object
300+
* @param role the role to associate to the {@code entity} object
301+
*/
302+
public static Acl of(Entity entity, Role role) {
303+
return new Acl(entity, role);
304+
}
305+
302306
@Override
303307
public int hashCode() {
304308
return Objects.hash(entity, role);
@@ -333,11 +337,11 @@ ObjectAccessControl toObjectPb() {
333337

334338
static Acl fromPb(ObjectAccessControl objectAccessControl) {
335339
Role role = Role.valueOf(objectAccessControl.getRole());
336-
return new Acl(Entity.fromPb(objectAccessControl.getEntity()), role);
340+
return Acl.of(Entity.fromPb(objectAccessControl.getEntity()), role);
337341
}
338342

339343
static Acl fromPb(BucketAccessControl bucketAccessControl) {
340344
Role role = Role.valueOf(bucketAccessControl.getRole());
341-
return new Acl(Entity.fromPb(bucketAccessControl.getEntity()), role);
345+
return Acl.of(Entity.fromPb(bucketAccessControl.getEntity()), role);
342346
}
343347
}

gcloud-java-storage/src/test/java/com/google/gcloud/storage/AclTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public void testRawEntity() {
8282

8383

8484
@Test
85-
public void testAcl() {
86-
Acl acl = new Acl(User.ofAllUsers(), Role.READER);
85+
public void testOf() {
86+
Acl acl = Acl.of(User.ofAllUsers(), Role.READER);
8787
assertEquals(User.ofAllUsers(), acl.entity());
8888
assertEquals(Role.READER, acl.role());
8989
ObjectAccessControl objectPb = acl.toObjectPb();

gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobInfoTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
public class BlobInfoTest {
3535

3636
private static final List<Acl> ACL = ImmutableList.of(
37-
new Acl(User.ofAllAuthenticatedUsers(), READER),
38-
new Acl(new Project(VIEWERS, "p1"), WRITER));
37+
Acl.of(User.ofAllAuthenticatedUsers(), READER),
38+
Acl.of(new Project(VIEWERS, "p1"), WRITER));
3939
private static final Integer COMPONENT_COUNT = 2;
4040
private static final String CONTENT_TYPE = "text/html";
4141
private static final String CACHE_CONTROL = "cache";

gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketInfoTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
public class BucketInfoTest {
4242

4343
private static final List<Acl> ACL = ImmutableList.of(
44-
new Acl(User.ofAllAuthenticatedUsers(), Role.READER),
45-
new Acl(new Project(VIEWERS, "p1"), Role.WRITER));
44+
Acl.of(User.ofAllAuthenticatedUsers(), Role.READER),
45+
Acl.of(new Project(VIEWERS, "p1"), Role.WRITER));
4646
private static final String ETAG = "0xFF00";
4747
private static final String ID = "B/N:1";
4848
private static final Long META_GENERATION = 10L;
@@ -51,7 +51,7 @@ public class BucketInfoTest {
5151
private static final Long CREATE_TIME = System.currentTimeMillis();
5252
private static final List<Cors> CORS = Collections.singletonList(Cors.builder().build());
5353
private static final List<Acl> DEFAULT_ACL =
54-
Collections.singletonList(new Acl(User.ofAllAuthenticatedUsers(), Role.WRITER));
54+
Collections.singletonList(Acl.of(User.ofAllAuthenticatedUsers(), Role.WRITER));
5555
private static final List<? extends DeleteRule> DELETE_RULES =
5656
Collections.singletonList(new AgeDeleteRule(5));
5757
private static final String INDEX_PAGE = "index.html";

gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class SerializationTest {
4747
private static final Acl.Project ACL_PROJECT_ = new Acl.Project(ProjectRole.VIEWERS, "pid");
4848
private static final Acl.User ACL_USER = new Acl.User("user");
4949
private static final Acl.RawEntity ACL_RAW = new Acl.RawEntity("raw");
50+
private static final Acl ACL = Acl.of(ACL_DOMAIN, Acl.Role.OWNER);
5051
private static final BlobInfo BLOB_INFO = BlobInfo.builder("b", "n").build();
5152
private static final BucketInfo BUCKET_INFO = BucketInfo.of("b");
5253
private static final Cors.Origin ORIGIN = Cors.Origin.any();
@@ -94,11 +95,10 @@ public void testServiceOptions() throws Exception {
9495

9596
@Test
9697
public void testModelAndRequests() throws Exception {
97-
Serializable[] objects = {ACL_DOMAIN, ACL_GROUP, ACL_PROJECT_, ACL_USER, ACL_RAW, BLOB_INFO,
98-
BUCKET_INFO,
99-
ORIGIN, CORS, BATCH_REQUEST, BATCH_RESPONSE, PAGE_RESULT, BLOB_LIST_OPTIONS,
100-
BLOB_SOURCE_OPTIONS, BLOB_TARGET_OPTIONS, BUCKET_LIST_OPTIONS, BUCKET_SOURCE_OPTIONS,
101-
BUCKET_TARGET_OPTIONS};
98+
Serializable[] objects = {ACL_DOMAIN, ACL_GROUP, ACL_PROJECT_, ACL_USER, ACL_RAW, ACL,
99+
BLOB_INFO, BUCKET_INFO, ORIGIN, CORS, BATCH_REQUEST, BATCH_RESPONSE, PAGE_RESULT,
100+
BLOB_LIST_OPTIONS, BLOB_SOURCE_OPTIONS, BLOB_TARGET_OPTIONS, BUCKET_LIST_OPTIONS,
101+
BUCKET_SOURCE_OPTIONS, BUCKET_TARGET_OPTIONS};
102102
for (Serializable obj : objects) {
103103
Object copy = serializeAndDeserialize(obj);
104104
assertEquals(obj, obj);

0 commit comments

Comments
 (0)