Skip to content

Commit d45009a

Browse files
Add service_url parameter to get_client and _get_bq_service
1 parent 4ab6674 commit d45009a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

bigquery/client.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import httplib2
1010
import six
11-
from apiclient.discovery import build
11+
from apiclient.discovery import build, DISCOVERY_URI
1212
from apiclient.errors import HttpError
1313

1414
from bigquery.errors import (BigQueryTimeoutException, JobExecutingException,
@@ -43,7 +43,8 @@
4343
JOB_DESTINATION_FORMAT_CSV = JOB_FORMAT_CSV
4444

4545

46-
def get_client(project_id, credentials=None, service_account=None,
46+
def get_client(project_id, credentials=None,
47+
service_url=None, service_account=None,
4748
private_key=None, private_key_file=None,
4849
json_key=None, json_key_file=None,
4950
readonly=True, swallow_results=True):
@@ -55,6 +56,12 @@ def get_client(project_id, credentials=None, service_account=None,
5556
project_id: the BigQuery project id.
5657
credentials: an AssertionCredentials instance to authenticate requests
5758
to BigQuery.
59+
service_url: a URI string template pointing to the location of
60+
Google's API discovery service. Requires two parameters
61+
{api} and {apiVersion} that when filled in produce an
62+
absolute URI to the discovery document for that service.
63+
If not set then the default googleapiclient disovery URI
64+
is used.
5865
service_account: the Google API service account name.
5966
private_key: the private key associated with the service account in
6067
PKCS12 or PEM format.
@@ -77,6 +84,9 @@ def get_client(project_id, credentials=None, service_account=None,
7784
assert (service_account and (private_key or private_key_file)) or (json_key or json_key_file), \
7885
'Must provide AssertionCredentials or service account and P12 key or JSON key'
7986

87+
if service_url is None:
88+
service_url = DISCOVERY_URI
89+
8090
if private_key_file:
8191
with open(private_key_file, 'rb') as key_file:
8292
private_key = key_file.read()
@@ -90,14 +100,15 @@ def get_client(project_id, credentials=None, service_account=None,
90100
private_key = json_key['private_key']
91101

92102
bq_service = _get_bq_service(credentials=credentials,
103+
service_url=service_url,
93104
service_account=service_account,
94105
private_key=private_key,
95106
readonly=readonly)
96107

97108
return BigQueryClient(bq_service, project_id, swallow_results)
98109

99110

100-
def _get_bq_service(credentials=None, service_account=None, private_key=None,
111+
def _get_bq_service(credentials=None, service_url=None, service_account=None, private_key=None,
101112
readonly=True):
102113
"""Construct an authorized BigQuery service object."""
103114

@@ -110,7 +121,7 @@ def _get_bq_service(credentials=None, service_account=None, private_key=None,
110121

111122
http = httplib2.Http()
112123
http = credentials.authorize(http)
113-
service = build('bigquery', 'v2', http=http)
124+
service = build('bigquery', 'v2', http=http, discoveryServiceUrl=service_url)
114125

115126
return service
116127

0 commit comments

Comments
 (0)