Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 01f2c1b

Browse files
Use Google Auth's load_credentials_from_* Methods
These methods handle services accounts as well any any other credential method. Got someone using DBT with AWS-based Auth (see #86)? This will work with AWS Auth. Typical service account auth with a key file and oauth2 jwt assertion grant stuff still works and is covered here: https://github.com/googleapis/google-auth-library-python/blob/v2.14.1/google/auth/_default.py#L408 I did add `google-auth>=2.20.0` which is the first version that has `load_credentials_from_dict`. Previously this lower bound was v2.14.1 (from `google-api-core>=2.11`). Basically this will just let folks auth bigquery however they would auth any gcloud resources without any extra effort. And the previous versions config still works exactly the same.
1 parent c489332 commit 01f2c1b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

dbt/adapters/bigquery/connections.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
import google.cloud.bigquery as bigquery
1919
import google.cloud.exceptions
2020
from google.api_core import retry, client_info
21-
from google.auth import impersonated_credentials
22-
from google.oauth2 import (
23-
credentials as GoogleCredentials,
24-
service_account as GoogleServiceAccountCredentials,
21+
from google.auth import (
22+
impersonated_credentials,
23+
load_credentials_from_file,
24+
load_credentials_from_dict,
2525
)
26-
26+
from google.oauth2 import credentials as GoogleCredentials,
2727
from dbt.adapters.bigquery import gcloud
2828
from dbt.clients import agate_helper
2929
from dbt.config.profile import INVALID_PROFILE_MESSAGE
@@ -332,19 +332,18 @@ def format_rows_number(self, rows_number):
332332
@classmethod
333333
def get_google_credentials(cls, profile_credentials) -> GoogleCredentials:
334334
method = profile_credentials.method
335-
creds = GoogleServiceAccountCredentials.Credentials
336335

337336
if method == BigQueryConnectionMethod.OAUTH:
338337
credentials, _ = get_bigquery_defaults(scopes=profile_credentials.scopes)
339338
return credentials
340339

341340
elif method == BigQueryConnectionMethod.SERVICE_ACCOUNT:
342341
keyfile = profile_credentials.keyfile
343-
return creds.from_service_account_file(keyfile, scopes=profile_credentials.scopes)
342+
return load_credentials_from_file(keyfile, scopes=profile_credentials.scopes)
344343

345344
elif method == BigQueryConnectionMethod.SERVICE_ACCOUNT_JSON:
346345
details = profile_credentials.keyfile_json
347-
return creds.from_service_account_info(details, scopes=profile_credentials.scopes)
346+
return load_credentials_from_dict(details, scopes=profile_credentials.scopes)
348347

349348
elif method == BigQueryConnectionMethod.OAUTH_SECRETS:
350349
return GoogleCredentials.Credentials(

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def _dbt_core_version(plugin_version: str) -> str:
8181
# ----
8282
# Expect compatibility with all new versions of these packages, so lower bounds only.
8383
"google-api-core>=2.11.0",
84+
"google-auth>=2.20.0",
8485
],
8586
zip_safe=False,
8687
classifiers=[

0 commit comments

Comments
 (0)