-
Notifications
You must be signed in to change notification settings - Fork 153
/
gcloud.py
28 lines (21 loc) · 727 Bytes
/
gcloud.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from dbt.common.events import AdapterLogger
import dbt.exceptions
from dbt.clients.system import run_cmd
NOT_INSTALLED_MSG = """
dbt requires the gcloud SDK to be installed to authenticate with BigQuery.
Please download and install the SDK, or use a Service Account instead.
https://cloud.google.com/sdk/
"""
logger = AdapterLogger("BigQuery")
def gcloud_installed():
try:
run_cmd(".", ["gcloud", "--version"])
return True
except OSError as e:
logger.debug(e)
return False
def setup_default_credentials():
if gcloud_installed():
run_cmd(".", ["gcloud", "auth", "application-default", "login"])
else:
raise dbt.exceptions.DbtRuntimeError(NOT_INSTALLED_MSG)