Skip to content

bq_update_dataset_access#1768

Merged
stephaniewang526 merged 3 commits into
GoogleCloudPlatform:masterfrom
stephaniewang526:bq-update-access-control
Dec 2, 2019
Merged

bq_update_dataset_access#1768
stephaniewang526 merged 3 commits into
GoogleCloudPlatform:masterfrom
stephaniewang526:bq-update-access-control

Conversation

@stephaniewang526

Copy link
Copy Markdown
Contributor

No description provided.

@stephaniewang526 stephaniewang526 requested a review from a team November 27, 2019 20:47
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 27, 2019
Acl newEntry = Acl.of(new User("sample.bigquery.dev@gmail.com"), Role.READER);
try {
acls.add(newEntry);
DatasetInfo.Builder builder = dataset.toBuilder();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically builders are used like this:

DatasetInfo dataset = dataset.toBuilder().setAcl(acls).build();

ArrayList<Acl> acls = new ArrayList<>(beforeAcls);
Acl newEntry = Acl.of(new User("sample.bigquery.dev@gmail.com"), Role.READER);
try {
acls.add(newEntry);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be moved out of the try/catch (see above comment). Generally, you should try to limit try/catches around where the exceptions actually occur.

BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();

Dataset dataset = bigquery.getDataset(datasetName);
List<Acl> beforeAcls = dataset.getAcl();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this throw an exception as well? Presumable it's making an API call underneath?

Dataset dataset = bigquery.getDataset(datasetName);
List<Acl> beforeAcls = dataset.getAcl();

// Make a copy of the ACLs so that they can be modified.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat misleading - you aren't making a copy of the ACLs, you are making a copy of the list (which still has references to the original ACL objects). The references in the list still point to the same objects.

Also, there's no reason to retain a link to the original list, because it doesn't get used anywhere.

Something like this might be better instead:

Suggested change
// Make a copy of the ACLs so that they can be modified.
// For more information on the types of ACLs available see:
// https://link.to.acl.docs
// Create a new ACL granting the READER role to "sample.bigquery.dev@gmail.com"
Acl newEntry = Acl.of(new Acl.User("sample.bigquery.dev@gmail.com"), Role.READER);
// Get a copy of the ACLs list from the dataset and append the new entry
ArrayList<Acl> acls = new ArrayList<>(dataset.getAcl());
acls.add(newEntry);
// Then down below add a comment like "Update the dataset to use the new ACLs".

@stephaniewang526 stephaniewang526 merged commit afb943e into GoogleCloudPlatform:master Dec 2, 2019
@stephaniewang526 stephaniewang526 deleted the bq-update-access-control branch December 2, 2019 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants