-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2517 from azhard/bigquery-auth-views
Added support for BigQuery authorized views
- Loading branch information
Showing
8 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -317,3 +317,4 @@ | |
{% macro set_sql_header(config) -%} | ||
{{ config.set('sql_header', caller()) }} | ||
{%- endmacro %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
|
||
{% macro date_sharded_table(base_name) %} | ||
{{ return(base_name ~ "[DBT__PARTITION_DATE]") }} | ||
{% endmacro %} | ||
|
||
{% macro grant_access_to(entity, entity_type, role, grant_target_dict) -%} | ||
{% do adapter.grant_access_to(entity, entity_type, role, grant_target_dict) %} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,3 +70,52 @@ def test_bigquery_adapter_methods(self): | |
}) | ||
self.run_dbt(['run-operation', 'rename_named_relation', '--args', rename_relation_args]) | ||
self.run_dbt() | ||
|
||
|
||
class TestGrantAccess(DBTIntegrationTest): | ||
@property | ||
def schema(self): | ||
return "grant_access_054" | ||
|
||
@property | ||
def models(self): | ||
return 'bigquery-models' | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
'config-version': 2, | ||
'source-paths': ['models'] | ||
} | ||
|
||
@use_profile('bigquery') | ||
def test_bigquery_adapter_methods(self): | ||
from dbt.adapters.bigquery import GrantTarget | ||
from google.cloud.bigquery import AccessEntry | ||
|
||
self.run_dbt(['compile']) # trigger any compile-time issues | ||
self.run_sql_file("seed_bq.sql") | ||
self.run_dbt(['seed']) | ||
|
||
ae_role = "READER" | ||
ae_entity = "[email protected]" | ||
ae_entity_type = "userByEmail" | ||
ae_grant_target_dict = { | ||
'project': self.default_database, | ||
'dataset': self.unique_schema() | ||
} | ||
self.adapter.grant_access_to(ae_entity, ae_entity_type, ae_role, ae_grant_target_dict) | ||
|
||
conn = self.adapter.connections.get_thread_connection() | ||
client = conn.handle | ||
|
||
grant_target = GrantTarget.from_dict(ae_grant_target_dict) | ||
dataset = client.get_dataset( | ||
self.adapter.connections.dataset_from_id(grant_target.render()) | ||
) | ||
|
||
expected_access_entry = AccessEntry(ae_role, ae_entity_type, ae_entity) | ||
self.assertTrue(expected_access_entry in dataset.access_entries) | ||
|
||
unexpected_access_entry = AccessEntry(ae_role, ae_entity_type, "[email protected]") | ||
self.assertFalse(unexpected_access_entry in dataset.access_entries) |