Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 361376e

Browse files
committed
add impersonate_service_account
1 parent 32d8bf0 commit 361376e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

data_diff/dbt_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ def set_connection(self):
359359
"driver": conn_type,
360360
"project": credentials.get("project"),
361361
"dataset": credentials.get("dataset"),
362+
"impersonate_service_account": credentials.get("impersonate_service_account"),
362363
}
363364

364365
self.threads = credentials.get("threads")

data_diff/sqeleton/databases/bigquery.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ def import_bigquery_service_account():
4242
return service_account
4343

4444

45+
def import_bigquery_service_account_impersonation():
46+
from google.auth import impersonated_credentials
47+
48+
return impersonated_credentials
49+
50+
4551
class Mixin_MD5(AbstractMixin_MD5):
4652
def md5_as_int(self, s: str) -> str:
4753
return f"cast(cast( ('0x' || substr(TO_HEX(md5({s})), 18)) as int64) as numeric)"
@@ -221,7 +227,14 @@ def __init__(self, project, *, dataset, bigquery_credentials=None, **kw):
221227
keyfile,
222228
scopes=["https://www.googleapis.com/auth/cloud-platform"],
223229
)
224-
230+
elif kw.get("impersonate_service_account"):
231+
bigquery_service_account_impersonation = import_bigquery_service_account_impersonation()
232+
credentials = bigquery_service_account_impersonation.Credentials(
233+
source_credentials=credentials,
234+
target_principal=kw["impersonate_service_account"],
235+
target_scopes=["https://www.googleapis.com/auth/cloud-platform"],
236+
)
237+
225238
self._client = bigquery.Client(project=project, credentials=credentials, **kw)
226239
self.project = project
227240
self.dataset = dataset

0 commit comments

Comments
 (0)