Skip to content

Commit a2d2bab

Browse files
fix(bigquery): fix typos and comments in cloud-client samples (#13231)
* fix(bigquery): fix typos and comments in cloud-client samples - Fix comments (for example 'grant' instead of 'revoke', or typos) - Remove unnecessary comments (For example in imports at the start of the sample) - Unify comments style * fix(bigquery): apply feedback from PR review
1 parent 7dbec66 commit a2d2bab

7 files changed

+19
-21
lines changed

bigquery/cloud-client/conftest.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
PREFIX = prefixer.create_prefix()
2525
ENTITY_ID = "cloud-developer-relations@google.com" # Group account
26-
DATASET_ID = f"{PREFIX}_cloud_client"
27-
TABLE_NAME = f"{PREFIX}_view_access_policies_table"
28-
VIEW_NAME = f"{PREFIX}_view_access_policies_view"
26+
DATASET_ID = f"{PREFIX}_access_policies_dataset"
27+
TABLE_NAME = f"{PREFIX}_access_policies_table"
28+
VIEW_NAME = f"{PREFIX}_access_policies_view"
2929

3030

3131
@pytest.fixture(scope="module")
@@ -70,8 +70,7 @@ def view(client: bigquery.Client, project_id: str, table: str) -> str:
7070
view = bigquery.Table(FULL_VIEW_NAME)
7171

7272
# f"{table}" will inject the full table name,
73-
# with project_id and dataset_id, as required by
74-
# .create_table()
73+
# with project_id and dataset_id, as required by create_table()
7574
view.view_query = f"SELECT * FROM `{table}`"
7675
view = client.create_table(view)
7776
return view

bigquery/cloud-client/grant_access_to_dataset.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ def grant_access_to_dataset(
2727

2828
# TODO(developer): Update and uncomment the lines below.
2929

30-
# ID of the dataset to revoke access to.
30+
# ID of the dataset to grant access to.
3131
# dataset_id = "my_project_id.my_dataset"
3232

33-
# ID of the user or group from whom you are adding access.
33+
# ID of the user or group receiving access to the dataset.
3434
# Alternatively, the JSON REST API representation of the entity,
35-
# such as a view's table reference.
35+
# such as the view's table reference.
3636
# entity_id = "user-or-group-to-add@example.com"
3737

3838
# One of the "Basic roles for datasets" described here:

bigquery/cloud-client/grant_access_to_table_or_view.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ def grant_access_to_table_or_view(
3737
# Table or view name to get the access policy.
3838
# resource_name = "my_table"
3939

40-
# The principal requesting access to the table or view.
41-
# Find more details about principal identifiers here:
40+
# Principal to grant access to a table or view.
41+
# For more information about principal identifiers see:
4242
# https://cloud.google.com/iam/docs/principal-identifiers
4343
# principal_id = "user:bob@example.com"
4444

45-
# Role to assign to the member.
45+
# Role to grant to the principal.
46+
# For more information about BigQuery roles see:
47+
# https://cloud.google.com/bigquery/docs/access-control
4648
# role = "roles/bigquery.dataViewer"
4749

4850
# Instantiate a client.
@@ -54,8 +56,7 @@ def grant_access_to_table_or_view(
5456
# Get the IAM access policy for the table or view.
5557
policy = client.get_iam_policy(full_resource_name)
5658

57-
# To grant access to a table or view,
58-
# add bindings to the Table or View policy.
59+
# To grant access to a table or view, add bindings to the IAM policy.
5960
#
6061
# Find more details about Policy and Binding objects here:
6162
# https://cloud.google.com/security-command-center/docs/reference/rest/Shared.Types/Policy
@@ -66,7 +67,7 @@ def grant_access_to_table_or_view(
6667
}
6768
policy.bindings.append(binding)
6869

69-
# Set the IAM access spolicy with updated bindings.
70+
# Set the IAM access policy with updated bindings.
7071
updated_policy = client.set_iam_policy(full_resource_name, policy)
7172

7273
# Show a success message.

bigquery/cloud-client/revoke_access_to_table_or_view.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def revoke_access_to_table_or_view(
2525
principal_to_remove: str | None = None,
2626
) -> Policy:
2727
# [START bigquery_revoke_access_to_table_or_view]
28-
# Imports the Google Cloud client library.
2928
from google.cloud import bigquery
3029

3130
# TODO(developer): Update and uncomment the lines below.
@@ -48,7 +47,7 @@ def revoke_access_to_table_or_view(
4847
# Find more information about roles and principals (referred to as members) here:
4948
# https://cloud.google.com/security-command-center/docs/reference/rest/Shared.Types/Binding
5049

51-
# Instantiates a client.
50+
# Instantiate a client.
5251
client = bigquery.Client()
5352

5453
# Get the full table name.
@@ -58,7 +57,7 @@ def revoke_access_to_table_or_view(
5857
policy = client.get_iam_policy(full_resource_name)
5958

6059
# To revoke access to a table or view,
61-
# remove bindings from the Table or View policy.
60+
# remove bindings from the Table or View IAM policy.
6261
#
6362
# Find more details about the Policy object here:
6463
# https://cloud.google.com/security-command-center/docs/reference/rest/Shared.Types/Policy

bigquery/cloud-client/revoke_dataset_access.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717

1818
def revoke_dataset_access(dataset_id: str, entity_id: str) -> list[AccessEntry]:
1919
# [START bigquery_revoke_dataset_access]
20-
# Import the Google Cloud client library.
2120
from google.cloud import bigquery
2221
from google.api_core.exceptions import PreconditionFailed
2322

2423
# TODO(developer): Update and uncomment the lines below.
2524

2625
# ID of the dataset to revoke access to.
27-
# dataset_id = "your-project.your_dataset"
26+
# dataset_id = "my-project.my_dataset"
2827

2928
# ID of the user or group from whom you are revoking access.
3029
# Alternatively, the JSON REST API representation of the entity,
@@ -61,6 +60,7 @@ def revoke_dataset_access(dataset_id: str, entity_id: str) -> list[AccessEntry]:
6160
["access_entries"],
6261
)
6362

63+
# Notify user that the API call was successful.
6464
full_dataset_id = f"{dataset.project}.{dataset.dataset_id}"
6565
print(f"Revoked dataset access for '{entity_id}' to ' dataset '{full_dataset_id}.'")
6666
except PreconditionFailed: # A read-modify-write error.

bigquery/cloud-client/view_dataset_access_policy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
def view_dataset_access_policy(dataset_id: str) -> list[AccessEntry]:
1919
# [START bigquery_view_dataset_access_policy]
20-
# Import the Google Cloud client library.
2120
from google.cloud import bigquery
2221

2322
# Instantiate a client.
@@ -38,6 +37,7 @@ def view_dataset_access_policy(dataset_id: str) -> list[AccessEntry]:
3837
f"{len(dataset.access_entries)} Access entries found "
3938
f"in dataset '{dataset_id}':"
4039
)
40+
4141
for access_entry in dataset.access_entries:
4242
print()
4343
print(f"Role: {access_entry.role}")

bigquery/cloud-client/view_table_or_view_access_policy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
def view_table_or_view_access_policy(project_id: str, dataset_id: str, resource_id: str) -> Policy:
1919
# [START bigquery_view_table_or_view_access_policy]
20-
# Imports the Google Cloud client library.
2120
from google.cloud import bigquery
2221

2322
# TODO(developer): Update and uncomment the lines below.

0 commit comments

Comments
 (0)