Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dbt-bigquery/src/dbt/adapters/bigquery/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from google.oauth2.credentials import Credentials as GoogleCredentials
from google.oauth2.service_account import Credentials as ServiceAccountCredentials
from google.auth.identity_pool import Credentials as IdentityPoolCredentials
from google.auth.credentials import AnonymousCredentials
from mashumaro import pass_through

from dbt_common.clients.system import run_cmd
Expand Down Expand Up @@ -42,6 +43,7 @@ class BigQueryConnectionMethod(StrEnum):
SERVICE_ACCOUNT_JSON = "service-account-json"
# WIF in this context refers to Workload Identity Federation https://cloud.google.com/iam/docs/workload-identity-federation
EXTERNAL_OAUTH_WIF = "external-oauth-wif"
ANONYMOUS = "anonymous"


@dataclass
Expand Down Expand Up @@ -248,6 +250,9 @@ def _create_google_credentials(credentials: BigQueryCredentials) -> GoogleCreden
elif credentials.method == BigQueryConnectionMethod.EXTERNAL_OAUTH_WIF:
creds = _create_identity_pool_credentials(credentials=credentials)

elif credentials.method == BigQueryConnectionMethod.ANONYMOUS:
creds = AnonymousCredentials()

else:
raise FailedToConnectError(f"Invalid `method` in profile: '{credentials.method}'")

Expand Down
29 changes: 29 additions & 0 deletions dbt-bigquery/tests/unit/test_bigquery_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ def setUp(self):
"compute_region": "europe-west1",
"submission_method": "serverless",
},
"anonymous_ok": {
"type": "bigquery",
"method": "anonymous",
"project": "dbt-unit-000000",
"schema": "dummy_schema",
"threads": 1,
"api_endpoint": "http://localhost:9050",
},
"anonymous_missing_api_endpoint": {
"type": "bigquery",
"method": "anonymous",
"project": "dbt-unit-000000",
"schema": "dummy_schema",
"threads": 1,
},
},
"target": "oauth",
}
Expand Down Expand Up @@ -407,6 +422,20 @@ def test_acquire_connection_maximum_bytes_billed(self, mock_open_connection):
connection.handle
mock_open_connection.assert_called_once()

@patch("dbt.adapters.bigquery.BigQueryConnectionManager.open", return_value=_bq_conn())
def test_acquire_connection_anonymous_validations(self, mock_open_connection):
adapter = self.get_adapter("anonymous_ok")
try:
connection = adapter.acquire_connection("dummy")
self.assertEqual(connection.type, "bigquery")

except dbt_common.exceptions.base.DbtValidationError as e:
self.fail("got DbtValidationError: {}".format(str(e)))

mock_open_connection.assert_not_called()
connection.handle
mock_open_connection.assert_called_once()

def test_cancel_open_connections_empty(self):
adapter = self.get_adapter("oauth")
self.assertEqual(len(list(adapter.cancel_open_connections())), 0)
Expand Down
Loading