Skip to content

Commit 0581c28

Browse files
author
Jon Wayne Parrott
authored
Switch from oauth2client to google-auth (googleapis#2726)
* Removes all use of oauth2client from every package and tests. * Updates core to use google-auth's default credentials, project ID, and scoping logic. * Updates bigtable to use google-auth's scoping logic.
1 parent 75c4115 commit 0581c28

40 files changed

Lines changed: 351 additions & 1398 deletions

File tree

bigquery/unit_tests/test_client.py

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _make_one(self, *args, **kw):
2828
def test_ctor(self):
2929
from google.cloud.bigquery._http import Connection
3030
PROJECT = 'PROJECT'
31-
creds = _Credentials()
31+
creds = object()
3232
http = object()
3333
client = self._make_one(project=PROJECT, credentials=creds, http=http)
3434
self.assertIsInstance(client._connection, Connection)
@@ -57,7 +57,7 @@ def test_list_projects_defaults(self):
5757
'friendlyName': 'Two'},
5858
]
5959
}
60-
creds = _Credentials()
60+
creds = object()
6161
client = self._make_one(PROJECT_1, creds)
6262
conn = client._connection = _Connection(DATA)
6363

@@ -86,7 +86,7 @@ def test_list_projects_explicit_response_missing_projects_key(self):
8686
PATH = 'projects'
8787
TOKEN = 'TOKEN'
8888
DATA = {}
89-
creds = _Credentials()
89+
creds = object()
9090
client = self._make_one(PROJECT, creds)
9191
conn = client._connection = _Connection(DATA)
9292

@@ -128,7 +128,7 @@ def test_list_datasets_defaults(self):
128128
'friendlyName': 'Two'},
129129
]
130130
}
131-
creds = _Credentials()
131+
creds = object()
132132
client = self._make_one(PROJECT, creds)
133133
conn = client._connection = _Connection(DATA)
134134

@@ -156,7 +156,7 @@ def test_list_datasets_explicit_response_missing_datasets_key(self):
156156
PATH = 'projects/%s/datasets' % PROJECT
157157
TOKEN = 'TOKEN'
158158
DATA = {}
159-
creds = _Credentials()
159+
creds = object()
160160
client = self._make_one(PROJECT, creds)
161161
conn = client._connection = _Connection(DATA)
162162

@@ -180,7 +180,7 @@ def test_dataset(self):
180180
from google.cloud.bigquery.dataset import Dataset
181181
PROJECT = 'PROJECT'
182182
DATASET = 'dataset_name'
183-
creds = _Credentials()
183+
creds = object()
184184
http = object()
185185
client = self._make_one(project=PROJECT, credentials=creds, http=http)
186186
dataset = client.dataset(DATASET)
@@ -190,7 +190,7 @@ def test_dataset(self):
190190

191191
def test_job_from_resource_unknown_type(self):
192192
PROJECT = 'PROJECT'
193-
creds = _Credentials()
193+
creds = object()
194194
client = self._make_one(PROJECT, creds)
195195
with self.assertRaises(ValueError):
196196
client.job_from_resource({'configuration': {'nonesuch': {}}})
@@ -304,7 +304,7 @@ def test_list_jobs_defaults(self):
304304
LOAD_DATA,
305305
]
306306
}
307-
creds = _Credentials()
307+
creds = object()
308308
client = self._make_one(PROJECT, creds)
309309
conn = client._connection = _Connection(DATA)
310310

@@ -360,7 +360,7 @@ def test_list_jobs_load_job_wo_sourceUris(self):
360360
LOAD_DATA,
361361
]
362362
}
363-
creds = _Credentials()
363+
creds = object()
364364
client = self._make_one(PROJECT, creds)
365365
conn = client._connection = _Connection(DATA)
366366

@@ -388,7 +388,7 @@ def test_list_jobs_explicit_missing(self):
388388
PATH = 'projects/%s/jobs' % PROJECT
389389
DATA = {}
390390
TOKEN = 'TOKEN'
391-
creds = _Credentials()
391+
creds = object()
392392
client = self._make_one(PROJECT, creds)
393393
conn = client._connection = _Connection(DATA)
394394

@@ -419,7 +419,7 @@ def test_load_table_from_storage(self):
419419
DATASET = 'dataset_name'
420420
DESTINATION = 'destination_table'
421421
SOURCE_URI = 'http://example.com/source.csv'
422-
creds = _Credentials()
422+
creds = object()
423423
http = object()
424424
client = self._make_one(project=PROJECT, credentials=creds, http=http)
425425
dataset = client.dataset(DATASET)
@@ -438,7 +438,7 @@ def test_copy_table(self):
438438
DATASET = 'dataset_name'
439439
SOURCE = 'source_table'
440440
DESTINATION = 'destination_table'
441-
creds = _Credentials()
441+
creds = object()
442442
http = object()
443443
client = self._make_one(project=PROJECT, credentials=creds, http=http)
444444
dataset = client.dataset(DATASET)
@@ -458,7 +458,7 @@ def test_extract_table_to_storage(self):
458458
DATASET = 'dataset_name'
459459
SOURCE = 'source_table'
460460
DESTINATION = 'gs://bucket_name/object_name'
461-
creds = _Credentials()
461+
creds = object()
462462
http = object()
463463
client = self._make_one(project=PROJECT, credentials=creds, http=http)
464464
dataset = client.dataset(DATASET)
@@ -475,7 +475,7 @@ def test_run_async_query_defaults(self):
475475
PROJECT = 'PROJECT'
476476
JOB = 'job_name'
477477
QUERY = 'select count(*) from persons'
478-
creds = _Credentials()
478+
creds = object()
479479
http = object()
480480
client = self._make_one(project=PROJECT, credentials=creds, http=http)
481481
job = client.run_async_query(JOB, QUERY)
@@ -511,7 +511,7 @@ def test_run_async_w_query_parameters(self):
511511
PROJECT = 'PROJECT'
512512
JOB = 'job_name'
513513
QUERY = 'select count(*) from persons'
514-
creds = _Credentials()
514+
creds = object()
515515
http = object()
516516
client = self._make_one(project=PROJECT, credentials=creds, http=http)
517517
query_parameters = [ScalarQueryParameter('foo', 'INT64', 123)]
@@ -575,19 +575,6 @@ def test_run_sync_query_w_query_parameters(self):
575575
self.assertEqual(query.query_parameters, query_parameters)
576576

577577

578-
class _Credentials(object):
579-
580-
_scopes = None
581-
582-
@staticmethod
583-
def create_scoped_required():
584-
return True
585-
586-
def create_scoped(self, scope):
587-
self._scopes = scope
588-
return self
589-
590-
591578
class _Connection(object):
592579

593580
def __init__(self, *responses):

bigtable/google/cloud/bigtable/client.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import os
3131

32+
import google.auth.credentials
3233
from google.longrunning import operations_grpc
3334

3435
from google.cloud._helpers import make_insecure_stub
@@ -201,14 +202,16 @@ def __init__(self, project=None, credentials=None,
201202
else:
202203
scopes.append(DATA_SCOPE)
203204

205+
self._read_only = bool(read_only)
206+
204207
if admin:
205208
scopes.append(ADMIN_SCOPE)
206209

207210
self._admin = bool(admin)
208-
try:
209-
credentials = credentials.create_scoped(scopes)
210-
except AttributeError:
211-
pass
211+
212+
credentials = google.auth.credentials.with_scopes_if_required(
213+
credentials, scopes)
214+
212215
self._credentials = credentials
213216
self.user_agent = user_agent
214217
self.emulator_host = os.getenv(BIGTABLE_EMULATOR)
@@ -229,12 +232,10 @@ def copy(self):
229232
:rtype: :class:`.Client`
230233
:returns: A copy of the current client.
231234
"""
232-
credentials = self._credentials
233-
copied_creds = credentials.create_scoped(credentials.scopes)
234235
return self.__class__(
235236
self.project,
236-
copied_creds,
237-
READ_ONLY_SCOPE in copied_creds.scopes,
237+
self._credentials,
238+
self._read_only,
238239
self._admin,
239240
self.user_agent,
240241
)

bigtable/tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ localdeps =
77
pip install --quiet --upgrade {toxinidir}/../core
88
deps =
99
{toxinidir}/../core
10+
mock
1011
pytest
1112
covercmd =
1213
py.test --quiet \

0 commit comments

Comments
 (0)