From db48dc81dad07e96aa87d2334277c73351e65daf Mon Sep 17 00:00:00 2001 From: stephwang Date: Thu, 30 Dec 2021 17:56:37 -0500 Subject: [PATCH 1/9] feat: add Dataset ACL support --- .../java/com/google/cloud/bigquery/Acl.java | 140 +++++++++++++++++- .../com/google/cloud/bigquery/AclTest.java | 15 ++ .../cloud/bigquery/it/ITBigQueryTest.java | 39 +++++ 3 files changed, 192 insertions(+), 2 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java index 48ff86342..97bf1540d 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java @@ -16,13 +16,21 @@ package com.google.cloud.bigquery; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Strings.isNullOrEmpty; import com.google.api.core.ApiFunction; import com.google.api.services.bigquery.model.Dataset.Access; +import com.google.api.services.bigquery.model.DatasetAccessEntry; +import com.google.api.services.bigquery.model.DatasetAccessEntry.TargetTypes; import com.google.cloud.StringEnumType; import com.google.cloud.StringEnumValue; +import com.google.cloud.bigquery.Acl.Dataset.DatasetAccessEntryTargetTypes; +import com.google.common.base.Function; +import com.google.common.collect.Lists; import java.io.Serializable; +import java.util.List; import java.util.Objects; /** @@ -92,7 +100,7 @@ public static Role[] values() { } /** Base class for BigQuery entities that can be grant access to the dataset. */ - public abstract static class Entity implements Serializable { + public abstract static class Entity /* TODO: ADD IT BACK*/ { private static final long serialVersionUID = 8111776788607959944L; @@ -105,7 +113,8 @@ public enum Type { USER, VIEW, IAM_MEMBER, - ROUTINE + ROUTINE, + DATASET } Entity(Type type) { @@ -119,6 +128,13 @@ public Type getType() { abstract Access toPb(); static Entity fromPb(Access access) { + if (access.getDataset() != null) { + return new Dataset( + DatasetId.fromPb(access.getDataset().getDataset()), + Lists.transform( + access.getDataset().getTargetTypes(), + DatasetAccessEntryTargetTypes.FROM_PB_FUNCTION)); + } if (access.getDomain() != null) { return new Domain(access.getDomain()); } @@ -146,6 +162,121 @@ static Entity fromPb(Access access) { } } + /** + * Class for a BigQuery Dataset entity. Objects of this class represent a dataset from a different + * dataset to grant access to. Only views are supported for now. The role field is not required + * when this field is set. If that dataset is deleted and re-created, its access needs to be + * granted again via an update operation. + */ + public static final class Dataset extends Entity { + + private static final long serialVersionUID = -8392885851733136526L; + + private final DatasetId id; + private final List targetTypes; + + /** Creates a Dataset entity given the dataset's id. */ + public Dataset(DatasetId id, List targetTypes) { + super(Type.DATASET); + this.id = id; + this.targetTypes = targetTypes; + } + + /** Returns dataset's identity. */ + public DatasetId getId() { + return id; + } + + public List getTargetTypes() { + return targetTypes; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + Dataset dataset = (Dataset) obj; + return Objects.equals(getType(), dataset.getType()) && Objects.equals(id, dataset.id); + } + + @Override + public int hashCode() { + return Objects.hash(getType(), id); + } + + @Override + public String toString() { + return toPb().toString(); + } + + @Override + Access toPb() { + return new Access() + .setDataset( + new DatasetAccessEntry() + .setDataset(id.toPb()) + .setTargetTypes( + targetTypes == null + ? null + : Lists.transform( + targetTypes, DatasetAccessEntryTargetTypes.TO_PB_FUNCTION))); + } + + /** Wrapper class for TargetTypes model class */ + public static final class DatasetAccessEntryTargetTypes { + + private final String targetType; + + public String getTargetType() { + return targetType; + } + + static final Function FROM_PB_FUNCTION = + DatasetAccessEntryTargetTypes::fromPb; + + static final Function TO_PB_FUNCTION = + DatasetAccessEntryTargetTypes::toPb; + + private DatasetAccessEntryTargetTypes(String targetType) { + checkArgument(!isNullOrEmpty(targetType), "Provided targetType is null or empty"); + this.targetType = targetType; + } + + public static DatasetAccessEntryTargetTypes of(String targetType) { + return new DatasetAccessEntryTargetTypes((targetType)); + } + + @Override + public boolean equals(Object obj) { + return obj == this + || obj instanceof DatasetAccessEntryTargetTypes + && Objects.equals(toPb(), ((DatasetAccessEntryTargetTypes) obj).toPb()); + } + + @Override + public int hashCode() { + return Objects.hash(targetType); + } + + @Override + public String toString() { + return toPb().toString(); + } + + TargetTypes toPb() { + return new TargetTypes().setTargetType(targetType); + } + + static DatasetAccessEntryTargetTypes fromPb(TargetTypes targetTypes) { + return new DatasetAccessEntryTargetTypes(targetTypes.getTargetType()); + } + } + } + /** * Class for a BigQuery Domain entity. Objects of this class represent a domain to grant access * to. Any users signed in with the domain specified will be granted the specified access. @@ -516,6 +647,11 @@ public static Acl of(Entity entity, Role role) { return new Acl(entity, role); } + /** Returns an Acl object for a dataset entity. */ + public static Acl of(Dataset dataset) { + return new Acl(dataset, null); + } + /** Returns an Acl object for a view entity. */ public static Acl of(View view) { return new Acl(view, null); diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java index 736803391..ddd81a49d 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import com.google.api.services.bigquery.model.Dataset; +import com.google.cloud.bigquery.Acl.Dataset.DatasetAccessEntryTargetTypes; import com.google.cloud.bigquery.Acl.Domain; import com.google.cloud.bigquery.Acl.Entity; import com.google.cloud.bigquery.Acl.Entity.Type; @@ -27,10 +28,24 @@ import com.google.cloud.bigquery.Acl.Role; import com.google.cloud.bigquery.Acl.User; import com.google.cloud.bigquery.Acl.View; +import com.google.common.collect.ImmutableList; +import java.util.List; import org.junit.Test; public class AclTest { + @Test + public void testDatasetEntity() { + DatasetId datasetId = DatasetId.of("dataset"); + List targetTypes = + ImmutableList.of(DatasetAccessEntryTargetTypes.of("VIEW")); + Acl.Dataset entity = new Acl.Dataset(datasetId, targetTypes); + assertEquals(datasetId, entity.getId()); + assertEquals(targetTypes, entity.getTargetTypes()); + Dataset.Access pb = entity.toPb(); + assertEquals(entity, Entity.fromPb(pb)); + } + @Test public void testDomainEntity() { Domain entity = new Domain("d1"); diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 479a80e89..30382e147 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -38,6 +38,7 @@ import com.google.cloud.Role; import com.google.cloud.ServiceOptions; import com.google.cloud.bigquery.Acl; +import com.google.cloud.bigquery.Acl.Dataset.DatasetAccessEntryTargetTypes; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption; import com.google.cloud.bigquery.BigQuery.DatasetField; @@ -1789,6 +1790,44 @@ public void testAuthorizeRoutine() { assertEquals(routineAcl, routineDataset.getAcl()); } + @Test + public void testAuthorizeDataset() { + String datasetName = RemoteBigQueryHelper.generateDatasetName(); + DatasetId datasetId = DatasetId.of(datasetName); + List targetTypes = + ImmutableList.of(DatasetAccessEntryTargetTypes.of("VIEWS")); + List acl = + ImmutableList.of( + Acl.of(new Acl.Group("projectOwners"), Acl.Role.OWNER), + Acl.of(new Acl.IamMember("allUsers"), Acl.Role.READER)); + DatasetInfo datasetInfo = + DatasetInfo.newBuilder(datasetId) + .setAcl(acl) + .setDescription("original Dataset for Dataset ACL test") + .build(); + Dataset dataset = bigquery.create(datasetInfo); + assertNotNull(dataset); + assertEquals(dataset.getDescription(), "original Dataset for Dataset ACL test"); + + String newDatasetName = RemoteBigQueryHelper.generateDatasetName(); + DatasetId newDatasetId = DatasetId.of(newDatasetName); + DatasetInfo newDatasetInfo = + DatasetInfo.newBuilder(newDatasetId) + .setDescription("new Dataset to be authorized by the original dataset") + .build(); + Dataset newDataset = bigquery.create(newDatasetInfo); + assertNotNull(newDataset); + assertEquals( + newDataset.getDescription(), "new Dataset to be authorized by the original dataset"); + List newDatasetAcl = new ArrayList<>(newDataset.getAcl()); + Acl.Dataset datasetEntity = new Acl.Dataset(datasetId, targetTypes); + newDatasetAcl.add(Acl.of(datasetEntity, Acl.Role.OWNER)); + LOG.info(newDatasetAcl.toString()); + // TODO: figure out why the line below is failing + // newDataset.toBuilder().setAcl(newDatasetAcl).build().update(); + // assertEquals(newDatasetAcl, dataset.getAcl()); + } + @Test public void testSingleStatementsQueryException() throws InterruptedException { String invalidQuery = From b8ef22626a97a146297f0b3bd50a0d8f438522dd Mon Sep 17 00:00:00 2001 From: stephwang Date: Tue, 4 Jan 2022 12:24:25 -0500 Subject: [PATCH 2/9] some lint updates --- .../cloud/bigquery/it/ITBigQueryTest.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 30382e147..e1ba67058 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -1801,31 +1801,31 @@ public void testAuthorizeDataset() { Acl.of(new Acl.Group("projectOwners"), Acl.Role.OWNER), Acl.of(new Acl.IamMember("allUsers"), Acl.Role.READER)); DatasetInfo datasetInfo = - DatasetInfo.newBuilder(datasetId) - .setAcl(acl) - .setDescription("original Dataset for Dataset ACL test") + DatasetInfo.newBuilder(datasetId).setAcl(acl).setDescription("shared Dataset").build(); + Dataset sharedDataset = bigquery.create(datasetInfo); + assertNotNull(sharedDataset); + assertEquals(sharedDataset.getDescription(), "shared Dataset"); + // Get the current metadata for the dataset you want to share by calling the datasets.get method + List sharedDatasetAcl = new ArrayList<>(sharedDataset.getAcl()); + + // Create a new dataset to be authorized + String authorizedDatasetName = RemoteBigQueryHelper.generateDatasetName(); + DatasetId authorizedDatasetId = DatasetId.of(authorizedDatasetName); + DatasetInfo authorizedDatasetInfo = + DatasetInfo.newBuilder(authorizedDatasetId) + .setDescription("new Dataset to be authorized by the sharedDataset") .build(); - Dataset dataset = bigquery.create(datasetInfo); - assertNotNull(dataset); - assertEquals(dataset.getDescription(), "original Dataset for Dataset ACL test"); - - String newDatasetName = RemoteBigQueryHelper.generateDatasetName(); - DatasetId newDatasetId = DatasetId.of(newDatasetName); - DatasetInfo newDatasetInfo = - DatasetInfo.newBuilder(newDatasetId) - .setDescription("new Dataset to be authorized by the original dataset") - .build(); - Dataset newDataset = bigquery.create(newDatasetInfo); - assertNotNull(newDataset); + Dataset authorizedDataset = bigquery.create(authorizedDatasetInfo); + assertNotNull(authorizedDataset); assertEquals( - newDataset.getDescription(), "new Dataset to be authorized by the original dataset"); - List newDatasetAcl = new ArrayList<>(newDataset.getAcl()); + authorizedDataset.getDescription(), "new Dataset to be authorized by the sharedDataset"); + + // Add the new DatasetAccessEntry object to the existing sharedDatasetAcl list Acl.Dataset datasetEntity = new Acl.Dataset(datasetId, targetTypes); - newDatasetAcl.add(Acl.of(datasetEntity, Acl.Role.OWNER)); - LOG.info(newDatasetAcl.toString()); + sharedDatasetAcl.add(Acl.of(datasetEntity)); // TODO: figure out why the line below is failing - // newDataset.toBuilder().setAcl(newDatasetAcl).build().update(); - // assertEquals(newDatasetAcl, dataset.getAcl()); + // sharedDataset.toBuilder().setAcl(sharedDatasetAcl).build().update(); + // assertEquals(sharedDatasetAcl, sharedDataset.getAcl()); } @Test From c3163f28f789628f0fe160ec797560515f1a4c45 Mon Sep 17 00:00:00 2001 From: stephwang Date: Tue, 4 Jan 2022 12:28:07 -0500 Subject: [PATCH 3/9] add back interface that was causing IDE issues --- .../src/main/java/com/google/cloud/bigquery/Acl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java index 97bf1540d..b9d34571e 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java @@ -100,7 +100,7 @@ public static Role[] values() { } /** Base class for BigQuery entities that can be grant access to the dataset. */ - public abstract static class Entity /* TODO: ADD IT BACK*/ { + public abstract static class Entity implements Serializable { private static final long serialVersionUID = 8111776788607959944L; From d9c1b6dcfba7f6d8d1a97a18fbcd6cb3723462db Mon Sep 17 00:00:00 2001 From: stephwang Date: Tue, 4 Jan 2022 16:29:34 -0500 Subject: [PATCH 4/9] fix recursive import issue --- .../java/com/google/cloud/bigquery/Acl.java | 75 +++++++++---------- .../com/google/cloud/bigquery/AclTest.java | 2 +- .../cloud/bigquery/it/ITBigQueryTest.java | 2 +- 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java index b9d34571e..1a26ff193 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java @@ -26,7 +26,6 @@ import com.google.api.services.bigquery.model.DatasetAccessEntry.TargetTypes; import com.google.cloud.StringEnumType; import com.google.cloud.StringEnumValue; -import com.google.cloud.bigquery.Acl.Dataset.DatasetAccessEntryTargetTypes; import com.google.common.base.Function; import com.google.common.collect.Lists; import java.io.Serializable; @@ -225,55 +224,55 @@ Access toPb() { : Lists.transform( targetTypes, DatasetAccessEntryTargetTypes.TO_PB_FUNCTION))); } + } - /** Wrapper class for TargetTypes model class */ - public static final class DatasetAccessEntryTargetTypes { + /** Wrapper class for TargetTypes model class */ + public static final class DatasetAccessEntryTargetTypes implements Serializable { - private final String targetType; + private final String targetType; - public String getTargetType() { - return targetType; - } + public String getTargetType() { + return targetType; + } - static final Function FROM_PB_FUNCTION = - DatasetAccessEntryTargetTypes::fromPb; + static final Function FROM_PB_FUNCTION = + DatasetAccessEntryTargetTypes::fromPb; - static final Function TO_PB_FUNCTION = - DatasetAccessEntryTargetTypes::toPb; + static final Function TO_PB_FUNCTION = + DatasetAccessEntryTargetTypes::toPb; - private DatasetAccessEntryTargetTypes(String targetType) { - checkArgument(!isNullOrEmpty(targetType), "Provided targetType is null or empty"); - this.targetType = targetType; - } + private DatasetAccessEntryTargetTypes(String targetType) { + checkArgument(!isNullOrEmpty(targetType), "Provided targetType is null or empty"); + this.targetType = targetType; + } - public static DatasetAccessEntryTargetTypes of(String targetType) { - return new DatasetAccessEntryTargetTypes((targetType)); - } + public static DatasetAccessEntryTargetTypes of(String targetType) { + return new DatasetAccessEntryTargetTypes((targetType)); + } - @Override - public boolean equals(Object obj) { - return obj == this - || obj instanceof DatasetAccessEntryTargetTypes - && Objects.equals(toPb(), ((DatasetAccessEntryTargetTypes) obj).toPb()); - } + @Override + public boolean equals(Object obj) { + return obj == this + || obj instanceof DatasetAccessEntryTargetTypes + && Objects.equals(toPb(), ((DatasetAccessEntryTargetTypes) obj).toPb()); + } - @Override - public int hashCode() { - return Objects.hash(targetType); - } + @Override + public int hashCode() { + return Objects.hash(targetType); + } - @Override - public String toString() { - return toPb().toString(); - } + @Override + public String toString() { + return toPb().toString(); + } - TargetTypes toPb() { - return new TargetTypes().setTargetType(targetType); - } + TargetTypes toPb() { + return new TargetTypes().setTargetType(targetType); + } - static DatasetAccessEntryTargetTypes fromPb(TargetTypes targetTypes) { - return new DatasetAccessEntryTargetTypes(targetTypes.getTargetType()); - } + static DatasetAccessEntryTargetTypes fromPb(TargetTypes targetTypes) { + return new DatasetAccessEntryTargetTypes(targetTypes.getTargetType()); } } diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java index ddd81a49d..b4cdeb030 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java @@ -19,7 +19,7 @@ import static org.junit.Assert.assertEquals; import com.google.api.services.bigquery.model.Dataset; -import com.google.cloud.bigquery.Acl.Dataset.DatasetAccessEntryTargetTypes; +import com.google.cloud.bigquery.Acl.DatasetAccessEntryTargetTypes; import com.google.cloud.bigquery.Acl.Domain; import com.google.cloud.bigquery.Acl.Entity; import com.google.cloud.bigquery.Acl.Entity.Type; diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index e1ba67058..910dc923a 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -38,7 +38,7 @@ import com.google.cloud.Role; import com.google.cloud.ServiceOptions; import com.google.cloud.bigquery.Acl; -import com.google.cloud.bigquery.Acl.Dataset.DatasetAccessEntryTargetTypes; +import com.google.cloud.bigquery.Acl.DatasetAccessEntryTargetTypes; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption; import com.google.cloud.bigquery.BigQuery.DatasetField; From 3adb4821ac27bf71d08554228ac7c7abeaefcd7b Mon Sep 17 00:00:00 2001 From: stephwang Date: Thu, 6 Jan 2022 17:59:40 -0500 Subject: [PATCH 5/9] debug --- .../bigquery/spi/v2/HttpBigQueryRpc.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java index 24d7dd6b0..0fba7cfd6 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java @@ -72,6 +72,10 @@ import java.math.BigInteger; import java.util.List; import java.util.Map; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; @InternalExtensionOnly public class HttpBigQueryRpc implements BigQueryRpc { @@ -242,6 +246,23 @@ public boolean deleteDataset(String projectId, String datasetId, Map @Override public Dataset patch(Dataset dataset, Map options) { + Logger logger = Logger.getLogger(HttpTransport.class.getName()); + logger.setLevel(Level.CONFIG); + logger.addHandler(new Handler() { + @Override + public void close() throws SecurityException { + } + @Override + public void flush() { + } + @Override + public void publish(LogRecord record) { + // Default ConsoleHandler will print >= INFO to System.err. + if (record.getLevel().intValue() < Level.INFO.intValue()) { + System.out.println("*****************STEPHWANG DEBUG*****************" + record.getMessage()); + } + } + }); try { DatasetReference reference = dataset.getDatasetReference(); return bigquery From 1933667b3cdc1deec26b760147f315fcf03ef0ff Mon Sep 17 00:00:00 2001 From: stephwang Date: Tue, 18 Jan 2022 19:52:18 -0500 Subject: [PATCH 6/9] update code based on pending discovery doc changes (cl/421673680) --- .../java/com/google/cloud/bigquery/Acl.java | 75 ++----------------- .../bigquery/spi/v2/HttpBigQueryRpc.java | 21 ------ .../com/google/cloud/bigquery/AclTest.java | 6 +- .../cloud/bigquery/SerializationTest.java | 8 +- .../cloud/bigquery/it/ITBigQueryTest.java | 20 ++--- 5 files changed, 23 insertions(+), 107 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java index 1a26ff193..f9cdd87f3 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java @@ -16,20 +16,14 @@ package com.google.cloud.bigquery; -import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Strings.isNullOrEmpty; import com.google.api.core.ApiFunction; import com.google.api.services.bigquery.model.Dataset.Access; import com.google.api.services.bigquery.model.DatasetAccessEntry; -import com.google.api.services.bigquery.model.DatasetAccessEntry.TargetTypes; import com.google.cloud.StringEnumType; import com.google.cloud.StringEnumValue; -import com.google.common.base.Function; -import com.google.common.collect.Lists; import java.io.Serializable; -import java.util.List; import java.util.Objects; /** @@ -130,9 +124,7 @@ static Entity fromPb(Access access) { if (access.getDataset() != null) { return new Dataset( DatasetId.fromPb(access.getDataset().getDataset()), - Lists.transform( - access.getDataset().getTargetTypes(), - DatasetAccessEntryTargetTypes.FROM_PB_FUNCTION)); + access.getDataset().getTargetTypes()); } if (access.getDomain() != null) { return new Domain(access.getDomain()); @@ -172,10 +164,10 @@ public static final class Dataset extends Entity { private static final long serialVersionUID = -8392885851733136526L; private final DatasetId id; - private final List targetTypes; + private final String targetTypes; /** Creates a Dataset entity given the dataset's id. */ - public Dataset(DatasetId id, List targetTypes) { + public Dataset(DatasetId id, String targetTypes) { super(Type.DATASET); this.id = id; this.targetTypes = targetTypes; @@ -186,7 +178,7 @@ public DatasetId getId() { return id; } - public List getTargetTypes() { + public String getTargetTypes() { return targetTypes; } @@ -215,64 +207,7 @@ public String toString() { @Override Access toPb() { return new Access() - .setDataset( - new DatasetAccessEntry() - .setDataset(id.toPb()) - .setTargetTypes( - targetTypes == null - ? null - : Lists.transform( - targetTypes, DatasetAccessEntryTargetTypes.TO_PB_FUNCTION))); - } - } - - /** Wrapper class for TargetTypes model class */ - public static final class DatasetAccessEntryTargetTypes implements Serializable { - - private final String targetType; - - public String getTargetType() { - return targetType; - } - - static final Function FROM_PB_FUNCTION = - DatasetAccessEntryTargetTypes::fromPb; - - static final Function TO_PB_FUNCTION = - DatasetAccessEntryTargetTypes::toPb; - - private DatasetAccessEntryTargetTypes(String targetType) { - checkArgument(!isNullOrEmpty(targetType), "Provided targetType is null or empty"); - this.targetType = targetType; - } - - public static DatasetAccessEntryTargetTypes of(String targetType) { - return new DatasetAccessEntryTargetTypes((targetType)); - } - - @Override - public boolean equals(Object obj) { - return obj == this - || obj instanceof DatasetAccessEntryTargetTypes - && Objects.equals(toPb(), ((DatasetAccessEntryTargetTypes) obj).toPb()); - } - - @Override - public int hashCode() { - return Objects.hash(targetType); - } - - @Override - public String toString() { - return toPb().toString(); - } - - TargetTypes toPb() { - return new TargetTypes().setTargetType(targetType); - } - - static DatasetAccessEntryTargetTypes fromPb(TargetTypes targetTypes) { - return new DatasetAccessEntryTargetTypes(targetTypes.getTargetType()); + .setDataset(new DatasetAccessEntry().setDataset(id.toPb()).setTargetTypes(targetTypes)); } } diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java index 0fba7cfd6..24d7dd6b0 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java @@ -72,10 +72,6 @@ import java.math.BigInteger; import java.util.List; import java.util.Map; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; @InternalExtensionOnly public class HttpBigQueryRpc implements BigQueryRpc { @@ -246,23 +242,6 @@ public boolean deleteDataset(String projectId, String datasetId, Map @Override public Dataset patch(Dataset dataset, Map options) { - Logger logger = Logger.getLogger(HttpTransport.class.getName()); - logger.setLevel(Level.CONFIG); - logger.addHandler(new Handler() { - @Override - public void close() throws SecurityException { - } - @Override - public void flush() { - } - @Override - public void publish(LogRecord record) { - // Default ConsoleHandler will print >= INFO to System.err. - if (record.getLevel().intValue() < Level.INFO.intValue()) { - System.out.println("*****************STEPHWANG DEBUG*****************" + record.getMessage()); - } - } - }); try { DatasetReference reference = dataset.getDatasetReference(); return bigquery diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java index b4cdeb030..9bac45ae1 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java @@ -19,7 +19,6 @@ import static org.junit.Assert.assertEquals; import com.google.api.services.bigquery.model.Dataset; -import com.google.cloud.bigquery.Acl.DatasetAccessEntryTargetTypes; import com.google.cloud.bigquery.Acl.Domain; import com.google.cloud.bigquery.Acl.Entity; import com.google.cloud.bigquery.Acl.Entity.Type; @@ -28,8 +27,6 @@ import com.google.cloud.bigquery.Acl.Role; import com.google.cloud.bigquery.Acl.User; import com.google.cloud.bigquery.Acl.View; -import com.google.common.collect.ImmutableList; -import java.util.List; import org.junit.Test; public class AclTest { @@ -37,8 +34,7 @@ public class AclTest { @Test public void testDatasetEntity() { DatasetId datasetId = DatasetId.of("dataset"); - List targetTypes = - ImmutableList.of(DatasetAccessEntryTargetTypes.of("VIEW")); + String targetTypes = "VIEWS"; Acl.Dataset entity = new Acl.Dataset(datasetId, targetTypes); assertEquals(datasetId, entity.getId()); assertEquals(targetTypes, entity.getTargetTypes()); diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java index 30bb0db0b..520d1ac8d 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java @@ -38,8 +38,6 @@ public class SerializationTest extends BaseSerializationTest { Acl.of(new Acl.View(TableId.of("project", "dataset", "table")), Acl.Role.WRITER); private static final Acl ROUTINE_ACCESS = Acl.of(new Acl.Routine(RoutineId.of("project", "dataset", "routine")), Acl.Role.WRITER); - private static final List ACCESS_RULES = - ImmutableList.of(DOMAIN_ACCESS, GROUP_ACCESS, VIEW_ACCESS, ROUTINE_ACCESS, USER_ACCESS); private static final Long CREATION_TIME = System.currentTimeMillis() - 10; private static final Long DEFAULT_TABLE_EXPIRATION = 100L; private static final String DESCRIPTION = "Description"; @@ -50,6 +48,11 @@ public class SerializationTest extends BaseSerializationTest { private static final String LOCATION = ""; private static final String SELF_LINK = "http://bigquery/p/d"; private static final DatasetId DATASET_ID = DatasetId.of("project", "dataset"); + private static final String TARGET_TYPES = "VIEWS"; + private static final Acl DATASET_ACCESS = Acl.of(new Acl.Dataset(DATASET_ID, TARGET_TYPES)); + private static final List ACCESS_RULES = + ImmutableList.of( + DOMAIN_ACCESS, GROUP_ACCESS, VIEW_ACCESS, ROUTINE_ACCESS, USER_ACCESS, DATASET_ACCESS); private static final DatasetInfo DATASET_INFO = DatasetInfo.newBuilder(DATASET_ID) .setAcl(ACCESS_RULES) @@ -228,6 +231,7 @@ protected Serializable[] serializableObjects() { USER_ACCESS, VIEW_ACCESS, ROUTINE_ACCESS, + DATASET_ACCESS, DATASET_ID, DATASET_INFO, TABLE_ID, diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 910dc923a..f703b1d4d 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -38,7 +38,6 @@ import com.google.cloud.Role; import com.google.cloud.ServiceOptions; import com.google.cloud.bigquery.Acl; -import com.google.cloud.bigquery.Acl.DatasetAccessEntryTargetTypes; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption; import com.google.cloud.bigquery.BigQuery.DatasetField; @@ -1793,9 +1792,9 @@ public void testAuthorizeRoutine() { @Test public void testAuthorizeDataset() { String datasetName = RemoteBigQueryHelper.generateDatasetName(); - DatasetId datasetId = DatasetId.of(datasetName); - List targetTypes = - ImmutableList.of(DatasetAccessEntryTargetTypes.of("VIEWS")); + DatasetId datasetId = DatasetId.of(PROJECT_ID, datasetName); + String targetTypes = "VIEWS"; + // Specify the acl which will be shared to the authorized dataset List acl = ImmutableList.of( Acl.of(new Acl.Group("projectOwners"), Acl.Role.OWNER), @@ -1810,7 +1809,7 @@ public void testAuthorizeDataset() { // Create a new dataset to be authorized String authorizedDatasetName = RemoteBigQueryHelper.generateDatasetName(); - DatasetId authorizedDatasetId = DatasetId.of(authorizedDatasetName); + DatasetId authorizedDatasetId = DatasetId.of(PROJECT_ID, authorizedDatasetName); DatasetInfo authorizedDatasetInfo = DatasetInfo.newBuilder(authorizedDatasetId) .setDescription("new Dataset to be authorized by the sharedDataset") @@ -1821,11 +1820,14 @@ public void testAuthorizeDataset() { authorizedDataset.getDescription(), "new Dataset to be authorized by the sharedDataset"); // Add the new DatasetAccessEntry object to the existing sharedDatasetAcl list - Acl.Dataset datasetEntity = new Acl.Dataset(datasetId, targetTypes); + Acl.Dataset datasetEntity = new Acl.Dataset(authorizedDatasetId, targetTypes); sharedDatasetAcl.add(Acl.of(datasetEntity)); - // TODO: figure out why the line below is failing - // sharedDataset.toBuilder().setAcl(sharedDatasetAcl).build().update(); - // assertEquals(sharedDatasetAcl, sharedDataset.getAcl()); + + // Update the dataset with the added authorization + Dataset updatedDataset = sharedDataset.toBuilder().setAcl(sharedDatasetAcl).build().update(); + + // Verify that the authorized dataset has been added + assertEquals(sharedDatasetAcl, updatedDataset.getAcl()); } @Test From 8e2c3a6c6ac68c003a685f20f584269f52eda39b Mon Sep 17 00:00:00 2001 From: stephwang Date: Thu, 20 Jan 2022 18:36:59 -0500 Subject: [PATCH 7/9] update code to reflect more changes (target_types should be List) based on pending discovery doc changes (cl/421673680) --- .../src/main/java/com/google/cloud/bigquery/Acl.java | 7 ++++--- .../src/test/java/com/google/cloud/bigquery/AclTest.java | 4 +++- .../java/com/google/cloud/bigquery/SerializationTest.java | 2 +- .../java/com/google/cloud/bigquery/it/ITBigQueryTest.java | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java index f9cdd87f3..d723f9983 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java @@ -24,6 +24,7 @@ import com.google.cloud.StringEnumType; import com.google.cloud.StringEnumValue; import java.io.Serializable; +import java.util.List; import java.util.Objects; /** @@ -164,10 +165,10 @@ public static final class Dataset extends Entity { private static final long serialVersionUID = -8392885851733136526L; private final DatasetId id; - private final String targetTypes; + private final List targetTypes; /** Creates a Dataset entity given the dataset's id. */ - public Dataset(DatasetId id, String targetTypes) { + public Dataset(DatasetId id, List targetTypes) { super(Type.DATASET); this.id = id; this.targetTypes = targetTypes; @@ -178,7 +179,7 @@ public DatasetId getId() { return id; } - public String getTargetTypes() { + public List getTargetTypes() { return targetTypes; } diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java index 9bac45ae1..18783f77b 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java @@ -27,6 +27,8 @@ import com.google.cloud.bigquery.Acl.Role; import com.google.cloud.bigquery.Acl.User; import com.google.cloud.bigquery.Acl.View; +import com.google.common.collect.ImmutableList; +import java.util.List; import org.junit.Test; public class AclTest { @@ -34,7 +36,7 @@ public class AclTest { @Test public void testDatasetEntity() { DatasetId datasetId = DatasetId.of("dataset"); - String targetTypes = "VIEWS"; + List targetTypes = ImmutableList.of("VIEWS"); Acl.Dataset entity = new Acl.Dataset(datasetId, targetTypes); assertEquals(datasetId, entity.getId()); assertEquals(targetTypes, entity.getTargetTypes()); diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java index 520d1ac8d..2a45294a6 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java @@ -48,7 +48,7 @@ public class SerializationTest extends BaseSerializationTest { private static final String LOCATION = ""; private static final String SELF_LINK = "http://bigquery/p/d"; private static final DatasetId DATASET_ID = DatasetId.of("project", "dataset"); - private static final String TARGET_TYPES = "VIEWS"; + private static final List TARGET_TYPES = ImmutableList.of("VIEWS"); private static final Acl DATASET_ACCESS = Acl.of(new Acl.Dataset(DATASET_ID, TARGET_TYPES)); private static final List ACCESS_RULES = ImmutableList.of( diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index f703b1d4d..58a59c39e 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -1793,7 +1793,7 @@ public void testAuthorizeRoutine() { public void testAuthorizeDataset() { String datasetName = RemoteBigQueryHelper.generateDatasetName(); DatasetId datasetId = DatasetId.of(PROJECT_ID, datasetName); - String targetTypes = "VIEWS"; + List targetTypes = ImmutableList.of("VIEWS"); // Specify the acl which will be shared to the authorized dataset List acl = ImmutableList.of( From 68469957923426813f006d3e7e27ef16831a2d0d Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 1 Feb 2022 23:16:59 +0000 Subject: [PATCH 8/9] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 776d50cde..778f24774 100644 --- a/README.md +++ b/README.md @@ -52,20 +52,20 @@ If you are using Maven without BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies ```Groovy -implementation platform('com.google.cloud:libraries-bom:24.1.1') +implementation platform('com.google.cloud:libraries-bom:24.2.0') implementation 'com.google.cloud:google-cloud-bigquery' ``` If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-bigquery:2.6.0' +implementation 'com.google.cloud:google-cloud-bigquery:2.7.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.6.0" +libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.7.1" ``` ## Authentication From dab1cc8c212ff7fc620f5e9b8f984fbefd02c44d Mon Sep 17 00:00:00 2001 From: stephwang Date: Wed, 2 Feb 2022 11:25:32 -0500 Subject: [PATCH 9/9] rename to address feedback --- .../java/com/google/cloud/bigquery/Acl.java | 44 ++++++++++--------- .../com/google/cloud/bigquery/AclTest.java | 3 +- .../cloud/bigquery/SerializationTest.java | 3 +- .../cloud/bigquery/it/ITBigQueryTest.java | 3 +- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java index d723f9983..115e001bd 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java @@ -123,7 +123,7 @@ public Type getType() { static Entity fromPb(Access access) { if (access.getDataset() != null) { - return new Dataset( + return new DatasetAclEntity( DatasetId.fromPb(access.getDataset().getDataset()), access.getDataset().getTargetTypes()); } @@ -155,26 +155,26 @@ static Entity fromPb(Access access) { } /** - * Class for a BigQuery Dataset entity. Objects of this class represent a dataset from a different - * dataset to grant access to. Only views are supported for now. The role field is not required - * when this field is set. If that dataset is deleted and re-created, its access needs to be - * granted again via an update operation. + * Class for a BigQuery DatasetAclEntity ACL entity. Objects of this class represent a + * DatasetAclEntity from a different DatasetAclEntity to grant access to. Only views are supported + * for now. The role field is not required when this field is set. If that DatasetAclEntity is + * deleted and re-created, its access needs to be granted again via an update operation. */ - public static final class Dataset extends Entity { + public static final class DatasetAclEntity extends Entity { private static final long serialVersionUID = -8392885851733136526L; private final DatasetId id; private final List targetTypes; - /** Creates a Dataset entity given the dataset's id. */ - public Dataset(DatasetId id, List targetTypes) { + /** Creates a DatasetAclEntity given the DatasetAclEntity's id. */ + public DatasetAclEntity(DatasetId id, List targetTypes) { super(Type.DATASET); this.id = id; this.targetTypes = targetTypes; } - /** Returns dataset's identity. */ + /** Returns DatasetAclEntity's identity. */ public DatasetId getId() { return id; } @@ -191,8 +191,9 @@ public boolean equals(Object obj) { if (obj == null || getClass() != obj.getClass()) { return false; } - Dataset dataset = (Dataset) obj; - return Objects.equals(getType(), dataset.getType()) && Objects.equals(id, dataset.id); + DatasetAclEntity datasetAclEntity = (DatasetAclEntity) obj; + return Objects.equals(getType(), datasetAclEntity.getType()) + && Objects.equals(id, datasetAclEntity.id); } @Override @@ -408,9 +409,10 @@ Access toPb() { /** * Class for a BigQuery View entity. Objects of this class represent a view from a different - * dataset to grant access to. Queries executed against that view will have read access to tables - * in this dataset. The role field is not required when this field is set. If that view is updated - * by any user, access to the view needs to be granted again via an update operation. + * datasetAclEntity to grant access to. Queries executed against that view will have read access + * to tables in this datasetAclEntity. The role field is not required when this field is set. If + * that view is updated by any user, access to the view needs to be granted again via an update + * operation. */ public static final class View extends Entity { @@ -459,10 +461,10 @@ Access toPb() { /** * Class for a BigQuery Routine entity. Objects of this class represent a routine from a different - * dataset to grant access to. Queries executed against that routine will have read access to - * views/tables/routines in this dataset. Only UDF is supported for now. The role field is not - * required when this field is set. If that routine is updated by any user, access to the routine - * needs to be granted again via an update operation. + * datasetAclEntity to grant access to. Queries executed against that routine will have read + * access to views/tables/routines in this datasetAclEntity. Only UDF is supported for now. The + * role field is not required when this field is set. If that routine is updated by any user, + * access to the routine needs to be granted again via an update operation. */ public static final class Routine extends Entity { @@ -582,9 +584,9 @@ public static Acl of(Entity entity, Role role) { return new Acl(entity, role); } - /** Returns an Acl object for a dataset entity. */ - public static Acl of(Dataset dataset) { - return new Acl(dataset, null); + /** Returns an Acl object for a datasetAclEntity. */ + public static Acl of(DatasetAclEntity datasetAclEntity) { + return new Acl(datasetAclEntity, null); } /** Returns an Acl object for a view entity. */ diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java index 18783f77b..30866c2b6 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/AclTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import com.google.api.services.bigquery.model.Dataset; +import com.google.cloud.bigquery.Acl.DatasetAclEntity; import com.google.cloud.bigquery.Acl.Domain; import com.google.cloud.bigquery.Acl.Entity; import com.google.cloud.bigquery.Acl.Entity.Type; @@ -37,7 +38,7 @@ public class AclTest { public void testDatasetEntity() { DatasetId datasetId = DatasetId.of("dataset"); List targetTypes = ImmutableList.of("VIEWS"); - Acl.Dataset entity = new Acl.Dataset(datasetId, targetTypes); + DatasetAclEntity entity = new DatasetAclEntity(datasetId, targetTypes); assertEquals(datasetId, entity.getId()); assertEquals(targetTypes, entity.getTargetTypes()); Dataset.Access pb = entity.toPb(); diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java index 2a45294a6..0b0cd0207 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java @@ -20,6 +20,7 @@ import com.google.cloud.NoCredentials; import com.google.cloud.PageImpl; import com.google.cloud.Restorable; +import com.google.cloud.bigquery.Acl.DatasetAclEntity; import com.google.cloud.bigquery.StandardTableDefinition.StreamingBuffer; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -49,7 +50,7 @@ public class SerializationTest extends BaseSerializationTest { private static final String SELF_LINK = "http://bigquery/p/d"; private static final DatasetId DATASET_ID = DatasetId.of("project", "dataset"); private static final List TARGET_TYPES = ImmutableList.of("VIEWS"); - private static final Acl DATASET_ACCESS = Acl.of(new Acl.Dataset(DATASET_ID, TARGET_TYPES)); + private static final Acl DATASET_ACCESS = Acl.of(new DatasetAclEntity(DATASET_ID, TARGET_TYPES)); private static final List ACCESS_RULES = ImmutableList.of( DOMAIN_ACCESS, GROUP_ACCESS, VIEW_ACCESS, ROUTINE_ACCESS, USER_ACCESS, DATASET_ACCESS); diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 1e52f7bec..b8051122f 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -38,6 +38,7 @@ import com.google.cloud.Role; import com.google.cloud.ServiceOptions; import com.google.cloud.bigquery.Acl; +import com.google.cloud.bigquery.Acl.DatasetAclEntity; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption; import com.google.cloud.bigquery.BigQuery.DatasetField; @@ -1928,7 +1929,7 @@ public void testAuthorizeDataset() { authorizedDataset.getDescription(), "new Dataset to be authorized by the sharedDataset"); // Add the new DatasetAccessEntry object to the existing sharedDatasetAcl list - Acl.Dataset datasetEntity = new Acl.Dataset(authorizedDatasetId, targetTypes); + DatasetAclEntity datasetEntity = new DatasetAclEntity(authorizedDatasetId, targetTypes); sharedDatasetAcl.add(Acl.of(datasetEntity)); // Update the dataset with the added authorization