Skip to content

Commit

Permalink
add client_options with default scopes to client (move-coop#969)
Browse files Browse the repository at this point in the history
* add client_options with default scopes to client

* move client options to init

* move client options documentation

---------
Co-authored-by: Willy Raedy <[email protected]>
Co-authored-by: Erica Renée Faulkenberry <[email protected]>
  • Loading branch information
graemelorimer authored Jan 23, 2024
1 parent d4e85ab commit 94e8ec8
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions parsons/google/google_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,32 @@ class GoogleBigQuery(DatabaseConnector):
then will use the default inferred environment.
location: str
Default geographic location for tables
client_options: dict
A dictionary containing any requested client options. Defaults to the required
scopes for making API calls against External tables stored in Google Drive.
Can be set to None if these permissions are not desired
"""

def __init__(self, app_creds=None, project=None, location=None):
def __init__(
self,
app_creds=None,
project=None,
location=None,
client_options: dict = {
"scopes": [
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/bigquery",
"https://www.googleapis.com/auth/cloud-platform",
]
},
):
self.app_creds = app_creds

setup_google_application_credentials(app_creds)

self.project = project
self.location = location
self.client_options = client_options

# We will not create the client until we need to use it, since creating the client
# without valid GOOGLE_APPLICATION_CREDENTIALS raises an exception.
Expand All @@ -170,7 +187,11 @@ def client(self):
"""
if not self._client:
# Create a BigQuery client to use to make the query
self._client = bigquery.Client(project=self.project, location=self.location)
self._client = bigquery.Client(
project=self.project,
location=self.location,
client_options=self.client_options,
)

return self._client

Expand Down

0 comments on commit 94e8ec8

Please sign in to comment.