diff --git a/README.md b/README.md index 36586621..6ab9af11 100644 --- a/README.md +++ b/README.md @@ -390,7 +390,7 @@ models: | Environment Variable | Example | Description | |----------------------------------------------|---------------------------|---------------------------------------------------------| -| `DATACONTRACT_BIGQUERY_ACCOUNT_INFO_JSON_PATH` | `~/service-access-key.json` | Service Access key as saved on key creation by BigQuery | +| `DATACONTRACT_BIGQUERY_ACCOUNT_INFO_JSON_PATH` | `~/service-access-key.json` | Service Access key as saved on key creation by BigQuery. If this environment variable isn't set, the cli tries to use `GOOGLE_APPLICATION_CREDENTIALS` as a fallback, so if you have that set for using their Python library anyway, it should work seamlessly. | diff --git a/datacontract/engines/soda/connections/bigquery.py b/datacontract/engines/soda/connections/bigquery.py index 4ecbd240..c614d6c2 100644 --- a/datacontract/engines/soda/connections/bigquery.py +++ b/datacontract/engines/soda/connections/bigquery.py @@ -6,10 +6,17 @@ # https://docs.soda.io/soda/connect-bigquery.html#authentication-methods def to_bigquery_soda_configuration(server): # with service account key, using an external json file + + # check for our own environment variable first + account_info = os.getenv("DATACONTRACT_BIGQUERY_ACCOUNT_INFO_JSON_PATH") + if account_info is None: + # but as a fallback look for the default google one + account_info = os.getenv("GOOGLE_APPLICATION_CREDENTIALS") + soda_configuration = { f"data_source {server.type}": { "type": "bigquery", - "account_info_json_path": os.getenv("DATACONTRACT_BIGQUERY_ACCOUNT_INFO_JSON_PATH"), + "account_info_json_path": account_info, "auth_scopes": ["https://www.googleapis.com/auth/bigquery"], "project_id": server.project, "dataset": server.dataset,