Untitled

mail@pastecode.io avatar
unknown
sql
7 months ago
740 B
3
Indexable
Never
from google.cloud import bigquery

# Instantiates a client
client = bigquery.Client()

# Lists all datasets in the project
datasets = client.list_datasets()

# Iterates over each dataset and retrieves its tables/views and authorized viewers
for dataset in datasets:
    print(f"Dataset ID: {dataset.dataset_id}")
    tables = client.list_tables(dataset)
    for table in tables:
        print(f"  Table/View ID: {table.table_id}")
        # Retrieves the authorized viewers for the table/view
        response = client.get_iam_policy(table.reference)
        for binding in response.bindings:
            if binding.role == "roles/bigquery.dataViewer":
                print(f"    Authorized viewer: {binding.members[0]}")