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

Commit 57a016d

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 0995665 commit 57a016d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

dbt/adapters/bigquery/credentials.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
from functools import lru_cache
55
from typing import Any, Dict, Iterable, Optional, Tuple, Union
66

7-
from google.auth import default
7+
from google.auth import default, load_credentials_from_file, load_credentials_from_dict
88
from google.auth.exceptions import DefaultCredentialsError
99
from google.auth.impersonated_credentials import Credentials as ImpersonatedCredentials
1010
from google.oauth2.credentials import Credentials as GoogleCredentials
11-
from google.oauth2.service_account import Credentials as ServiceAccountCredentials
1211
from mashumaro import pass_through
1312

1413
from dbt_common.clients.system import run_cmd
@@ -197,15 +196,15 @@ def _create_google_credentials(credentials: BigQueryCredentials) -> GoogleCreden
197196
creds, _ = _create_bigquery_defaults(scopes=credentials.scopes)
198197

199198
elif credentials.method == _BigQueryConnectionMethod.SERVICE_ACCOUNT:
200-
creds = ServiceAccountCredentials.from_service_account_file(
199+
creds, _ = load_credentials_from_file(
201200
credentials.keyfile, scopes=credentials.scopes
202201
)
203202

204203
elif credentials.method == _BigQueryConnectionMethod.SERVICE_ACCOUNT_JSON:
205204
details = credentials.keyfile_json
206205
if _is_base64(details): # type:ignore
207206
details = _base64_to_string(details)
208-
creds = ServiceAccountCredentials.from_service_account_info(
207+
creds, _ = load_credentials_from_dict(
209208
details, scopes=credentials.scopes
210209
)
211210

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies = [
3131
"google-cloud-dataproc~=5.0",
3232
# ----
3333
# Expect compatibility with all new versions of these packages, so lower bounds only.
34+
"google-auth>=2.20.0",
3435
"google-api-core>=2.11.0",
3536
# add dbt-core to ensure backwards compatibility of installation, this is not a functional dependency
3637
"dbt-core>=1.8.0",

0 commit comments

Comments
 (0)