diff --git a/bigquery/cloud-client/grant_access_to_dataset.py b/bigquery/cloud-client/grant_access_to_dataset.py index a9bd4496bba..76e82f809d4 100644 --- a/bigquery/cloud-client/grant_access_to_dataset.py +++ b/bigquery/cloud-client/grant_access_to_dataset.py @@ -25,7 +25,7 @@ def grant_access_to_dataset( from google.cloud import bigquery from google.cloud.bigquery.enums import EntityTypes - # TODO(developer): Update and un-comment below lines + # TODO(developer): Update and uncomment the lines below. # ID of the dataset to revoke access to. # dataset_id = "my_project_id.my_dataset" diff --git a/bigquery/cloud-client/grant_access_to_table_or_view.py b/bigquery/cloud-client/grant_access_to_table_or_view.py index 87936abf764..c70fef980d8 100644 --- a/bigquery/cloud-client/grant_access_to_table_or_view.py +++ b/bigquery/cloud-client/grant_access_to_table_or_view.py @@ -26,7 +26,7 @@ def grant_access_to_table_or_view( # [START bigquery_grant_access_to_table_or_view] from google.cloud import bigquery - # TODO(developer): Update and un-comment below lines + # TODO(developer): Update and uncomment the lines below. # Google Cloud Platform project. # project_id = "my_project_id" @@ -66,7 +66,7 @@ def grant_access_to_table_or_view( } policy.bindings.append(binding) - # Set the IAM acces spolicy with updated bindings + # Set the IAM access spolicy with updated bindings. updated_policy = client.set_iam_policy(full_resource_name, policy) # Show a success message. diff --git a/bigquery/cloud-client/revoke_access_to_table_or_view.py b/bigquery/cloud-client/revoke_access_to_table_or_view.py index 4d6314a3a25..6ba87250321 100644 --- a/bigquery/cloud-client/revoke_access_to_table_or_view.py +++ b/bigquery/cloud-client/revoke_access_to_table_or_view.py @@ -28,7 +28,8 @@ def revoke_access_to_table_or_view( # Imports the Google Cloud client library. from google.cloud import bigquery - # TODO(developer): Update and un-comment below lines + # TODO(developer): Update and uncomment the lines below. + # Google Cloud Platform project. # project_id = "my_project_id" @@ -44,7 +45,7 @@ def revoke_access_to_table_or_view( # (Optional) Principal to revoke access to the table or view. # principal_to_remove = "user:alice@example.com" - # Find more information about roles and principals (refered as members) here: + # Find more information about roles and principals (referred to as members) here: # https://cloud.google.com/security-command-center/docs/reference/rest/Shared.Types/Binding # Instantiates a client. diff --git a/bigquery/cloud-client/revoke_access_to_table_or_view_test.py b/bigquery/cloud-client/revoke_access_to_table_or_view_test.py index e9dc1747503..6c5f1fa37a6 100644 --- a/bigquery/cloud-client/revoke_access_to_table_or_view_test.py +++ b/bigquery/cloud-client/revoke_access_to_table_or_view_test.py @@ -23,7 +23,6 @@ def test_revoke_access_to_table_or_view_for_role( client: bigquery.Client, dataset: Dataset, - project_id: str, table: Table, entity_id: str, ) -> None: @@ -34,7 +33,7 @@ def test_revoke_access_to_table_or_view_for_role( assert not empty_policy.bindings policy_with_role = grant_access_to_table_or_view( - project_id, + dataset.project, dataset.dataset_id, table.table_id, principal_id=PRINCIPAL_ID, @@ -45,7 +44,7 @@ def test_revoke_access_to_table_or_view_for_role( assert any(p for p in policy_with_role if p["role"] == ROLE) policy_with_revoked_role = revoke_access_to_table_or_view( - project_id, + dataset.project, dataset.dataset_id, resource_name=table.table_id, role_to_remove=ROLE, diff --git a/bigquery/cloud-client/revoke_dataset_access.py b/bigquery/cloud-client/revoke_dataset_access.py index 18bfd744e79..30840887183 100644 --- a/bigquery/cloud-client/revoke_dataset_access.py +++ b/bigquery/cloud-client/revoke_dataset_access.py @@ -21,7 +21,7 @@ def revoke_dataset_access(dataset_id: str, entity_id: str) -> list[AccessEntry]: from google.cloud import bigquery from google.api_core.exceptions import PreconditionFailed - # TODO(developer): Update and un-comment below lines + # TODO(developer): Update and uncomment the lines below. # ID of the dataset to revoke access to. # dataset_id = "your-project.your_dataset" @@ -63,7 +63,7 @@ def revoke_dataset_access(dataset_id: str, entity_id: str) -> list[AccessEntry]: full_dataset_id = f"{dataset.project}.{dataset.dataset_id}" print(f"Revoked dataset access for '{entity_id}' to ' dataset '{full_dataset_id}.'") - except PreconditionFailed: # A read-modify-write error + except PreconditionFailed: # A read-modify-write error. print( f"Dataset '{dataset.dataset_id}' was modified remotely before this update. " "Fetch the latest version and retry." diff --git a/bigquery/cloud-client/view_dataset_access_policy.py b/bigquery/cloud-client/view_dataset_access_policy.py index fd407b5dd6c..9c3bb54e2a8 100644 --- a/bigquery/cloud-client/view_dataset_access_policy.py +++ b/bigquery/cloud-client/view_dataset_access_policy.py @@ -23,8 +23,9 @@ def view_dataset_access_policy(dataset_id: str) -> list[AccessEntry]: # Instantiate a client. client = bigquery.Client() - # TODO(developer): Update and un-comment below lines - # Dataset from which to get the access policy + # TODO(developer): Update and uncomment the lines below. + + # Dataset from which to get the access policy. # dataset_id = "my_dataset" # Get a reference to the dataset. @@ -33,7 +34,10 @@ def view_dataset_access_policy(dataset_id: str) -> list[AccessEntry]: # Show the list of AccessEntry objects. # More details about the AccessEntry object here: # https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.dataset.AccessEntry - print(f"{len(dataset.access_entries)} Access entries in dataset '{dataset_id}':") + print( + f"{len(dataset.access_entries)} Access entries found " + f"in dataset '{dataset_id}':" + ) for access_entry in dataset.access_entries: print() print(f"Role: {access_entry.role}") diff --git a/bigquery/cloud-client/view_table_or_view_access_policy.py b/bigquery/cloud-client/view_table_or_view_access_policy.py index e4f06459cce..8040d3d6898 100644 --- a/bigquery/cloud-client/view_table_or_view_access_policy.py +++ b/bigquery/cloud-client/view_table_or_view_access_policy.py @@ -15,32 +15,35 @@ from google.api_core.iam import Policy -def view_table_or_view_access_policy(project_id: str, dataset_id: str, resource_name: str) -> Policy: +def view_table_or_view_access_policy(project_id: str, dataset_id: str, resource_id: str) -> Policy: # [START bigquery_view_table_or_view_access_policy] - # Imports the Google Cloud client library + # Imports the Google Cloud client library. from google.cloud import bigquery - # TODO(developer): Update and un-comment below lines + # TODO(developer): Update and uncomment the lines below. + # Google Cloud Platform project. # project_id = "my_project_id" + # Dataset where the table or view is. # dataset_id = "my_dataset_id" - # Table or view name to get the access policy. - # resource_name = "my_table_name" + + # Table or view from which to get the access policy. + # resource_id = "my_table_id" # Instantiate a client. client = bigquery.Client() - # Get the full table or view name. - full_resource_name = f"{project_id}.{dataset_id}.{resource_name}" + # Get the full table or view id. + full_resource_id = f"{project_id}.{dataset_id}.{resource_id}" # Get the IAM access policy for the table or view. - policy = client.get_iam_policy(full_resource_name) + policy = client.get_iam_policy(full_resource_id) # Show policy details. # Find more details for the Policy object here: # https://cloud.google.com/bigquery/docs/reference/rest/v2/Policy - print(f"Access Policy details for table or view '{resource_name}'.") + print(f"Access Policy details for table or view '{resource_id}'.") print(f"Bindings: {policy.bindings}") print(f"etag: {policy.etag}") print(f"Version: {policy.version}") diff --git a/bigquery/cloud-client/view_table_or_view_access_policy_test.py b/bigquery/cloud-client/view_table_or_view_access_policy_test.py index 63f67e94e21..46e822a298f 100644 --- a/bigquery/cloud-client/view_table_or_view_access_policy_test.py +++ b/bigquery/cloud-client/view_table_or_view_access_policy_test.py @@ -29,7 +29,7 @@ def test_view_dataset_access_policies_with_table( policy: Policy = view_table_or_view_access_policy(project_id, dataset.dataset_id, table.table_id) assert policy.etag == EMPTY_POLICY_ETAG - assert not policy.bindings # Bindings list is empty + assert not policy.bindings # Empty bindings list def test_view_dataset_access_policies_with_view( @@ -40,4 +40,4 @@ def test_view_dataset_access_policies_with_view( policy: Policy = view_table_or_view_access_policy(project_id, dataset.dataset_id, view.table_id) assert policy.etag == EMPTY_POLICY_ETAG - assert not policy.bindings # Bindings list is empty + assert not policy.bindings # Empty bindings list