Skip to content

Commit

Permalink
Merge pull request #14 from Marty08/marty
Browse files Browse the repository at this point in the history
added python function to readme for looping
  • Loading branch information
christippett authored Jun 13, 2020
2 parents 935b8c7 + 7e73304 commit 14fbc30
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $ bqva --help
[![asciicast](https://asciinema.org/a/252724.svg)](https://asciinema.org/a/252724)


### Example
### Example: CLI

![Example tree](/docs/example.png)

Expand Down Expand Up @@ -86,3 +86,38 @@ bqva-demo:dataset_4.shared_view
└── bqva-demo:dataset_2.view_d (⨯)
└── bqva-demo:dataset_3.table_d (⨯)
```
### Example: Python library

You can import the library within a Python project to programatically apply permissions to multiple datasets.

```python

from bigquery_view_analyzer import ViewAnalyzer
from google.cloud import bigquery

client = bigquery.Client()


def auth_views(datasets=[], **kwargs):
# get all datasets by default if none provided
if len(datasets) == 0:
datasets = client.list_datasets(max_results=1)
for dataset in datasets:
dataset = client.dataset(dataset)
tables = client.list_tables(dataset.dataset_id)
for table in tables:
if table.table_type == "VIEW":
view = ViewAnalyzer(
project_id=table.project,
dataset_id=table.dataset_id,
view_id=table.table_id,
)
view.apply_permissions()
print(
f"Authorised view: {table.project}.{table.dataset_id}.{table.table_id}"
)


auth_views(["dataset_a", "dataset_b"])

```

0 comments on commit 14fbc30

Please sign in to comment.