feat(bigquery): support IAM conditions in datasets in Java client. by whuffman36 · Pull Request #3602 · googleapis/java-bigquery · GitHub
Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,24 @@ public static DatasetOption fields(DatasetField... fields) {
return new DatasetOption(
BigQueryRpc.Option.FIELDS, Helper.selector(DatasetField.REQUIRED_FIELDS, fields));
}

/**
* Returns an option to specify the dataset's access policy version for conditional access. If
* this option is not provided the field remains unset and conditional access cannot be used.
* Valid values are 0, 1, and 3. Requests specifying an invalid value will be rejected. Requests
* for conditional access policy binding in datasets must specify version 3. Datasets with no
* conditional role bindings in access policy may specify any valid value or leave the field
* unset. This field will be mapped to <a
* href="https://cloud.google.com/iam/docs/policies#versions">IAM Policy version</a> and will be
* used to fetch the policy from IAM. If unset or if 0 or 1 the value is used for a dataset with
* conditional bindings, access entry with condition will have role string appended by
* 'withcond' string followed by a hash value. Please refer to <a
* href="https://cloud.google.com/iam/docs/troubleshooting-withcond">Troubleshooting
* withcond</a> for more details.
*/
public static DatasetOption accessPolicyVersion(Integer accessPolicyVersion) {
Comment thread
PhongChuong marked this conversation as resolved.
return new DatasetOption(BigQueryRpc.Option.ACCESS_POLICY_VERSION, accessPolicyVersion);
}
}

/** Class for specifying dataset delete options. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ enum Option {
REQUESTED_POLICY_VERSION("requestedPolicyVersion"),
TABLE_METADATA_VIEW("view"),
RETRY_OPTIONS("retryOptions"),
BIGQUERY_RETRY_CONFIG("bigQueryRetryConfig");
BIGQUERY_RETRY_CONFIG("bigQueryRetryConfig"),
ACCESS_POLICY_VERSION("accessPolicyVersion");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,19 @@ private void validateRPC() throws BigQueryException, IOException {
public Dataset getDataset(String projectId, String datasetId, Map<Option, ?> options) {
try {
validateRPC();
return bigquery
.datasets()
.get(projectId, datasetId)
.setFields(Option.FIELDS.getString(options))
.setPrettyPrint(false)
.execute();

Bigquery.Datasets.Get bqGetRequest =
bigquery
.datasets()
.get(projectId, datasetId)
.setFields(Option.FIELDS.getString(options))
.setPrettyPrint(false);
for (Map.Entry<Option, ?> entry : options.entrySet()) {
if (entry.getKey() == Option.ACCESS_POLICY_VERSION && entry.getValue() != null) {
bqGetRequest.setAccessPolicyVersion((Integer) entry.getValue());
}
}
return bqGetRequest.execute();
} catch (IOException ex) {
BigQueryException serviceException = translate(ex);
if (serviceException.getCode() == HTTP_NOT_FOUND) {
Expand Down Expand Up @@ -174,12 +181,18 @@ public Tuple<String, Iterable<Dataset>> listDatasets(String projectId, Map<Optio
public Dataset create(Dataset dataset, Map<Option, ?> options) {
try {
validateRPC();
return bigquery
.datasets()
.insert(dataset.getDatasetReference().getProjectId(), dataset)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options))
.execute();
Bigquery.Datasets.Insert bqCreateRequest =
bigquery
.datasets()
.insert(dataset.getDatasetReference().getProjectId(), dataset)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options));
for (Map.Entry<Option, ?> entry : options.entrySet()) {
if (entry.getKey() == Option.ACCESS_POLICY_VERSION && entry.getValue() != null) {
bqCreateRequest.setAccessPolicyVersion((Integer) entry.getValue());
}
}
return bqCreateRequest.execute();
} catch (IOException ex) {
throw translate(ex);
}
Expand Down Expand Up @@ -277,12 +290,18 @@ public Dataset patch(Dataset dataset, Map<Option, ?> options) {
try {
validateRPC();
DatasetReference reference = dataset.getDatasetReference();
return bigquery
.datasets()
.patch(reference.getProjectId(), reference.getDatasetId(), dataset)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options))
.execute();
Bigquery.Datasets.Patch bqPatchRequest =
bigquery
.datasets()
.patch(reference.getProjectId(), reference.getDatasetId(), dataset)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options));
for (Map.Entry<Option, ?> entry : options.entrySet()) {
if (entry.getKey() == Option.ACCESS_POLICY_VERSION && entry.getValue() != null) {
bqPatchRequest.setAccessPolicyVersion((Integer) entry.getValue());
}
}
return bqPatchRequest.execute();
} catch (IOException ex) {
throw translate(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.cloud.bigquery.Acl.Domain;
import com.google.cloud.bigquery.Acl.Entity;
import com.google.cloud.bigquery.Acl.Entity.Type;
import com.google.cloud.bigquery.Acl.Expr;
import com.google.cloud.bigquery.Acl.Group;
import com.google.cloud.bigquery.Acl.IamMember;
import com.google.cloud.bigquery.Acl.Role;
Expand Down Expand Up @@ -136,4 +137,13 @@ public void testOf() {
assertEquals(routine, acl.getEntity());
assertEquals(null, acl.getRole());
}

@Test
public void testOfWithCondition() {
Expr expr = new Expr("expression", "title", "description", "location");
Acl acl = Acl.of(Group.ofAllAuthenticatedUsers(), Role.READER, expr);
Dataset.Access pb = acl.toPb();
assertEquals(acl, Acl.fromPb(pb));
assertEquals(acl.getCondition(), expr);
}
}
Loading