Skip to content

Commit b93a661

Browse files
committed
Move '_helpers.get_scoped_connection' -> 'connection.
1 parent 7c51273 commit b93a661

File tree

6 files changed

+48
-49
lines changed

6 files changed

+48
-49
lines changed

gcloud/_helpers.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class Local(object):
3131
except ImportError:
3232
app_identity = None
3333

34-
from gcloud import credentials
35-
3634

3735
class _LocalStack(Local):
3836
"""Manage a thread-local LIFO stack of resources.
@@ -238,20 +236,3 @@ def __init__(self, project=None, implicit=False):
238236

239237

240238
_DEFAULTS = _DefaultsContainer(implicit=True)
241-
242-
243-
def get_scoped_connection(klass, scopes):
244-
"""Create a scoped connection to GCloud.
245-
246-
:type klass: type
247-
:param klass: the specific ``Connection`` class to instantiate.
248-
249-
:type scopes: list of URLs
250-
:param scopes: the effective service auth scopes for the connection.
251-
252-
:rtype: instance of ``klass``
253-
:returns: A connection defined with the proper credentials.
254-
"""
255-
implicit_credentials = credentials.get_credentials()
256-
scoped_credentials = implicit_credentials.create_scoped(scopes)
257-
return klass(credentials=scoped_credentials)

gcloud/connection.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import httplib2
2222

23+
from gcloud.credentials import get_credentials
2324
from gcloud.exceptions import make_exception
2425

2526

@@ -297,3 +298,20 @@ def api_request(self, method, path, query_params=None,
297298
return json.loads(content)
298299

299300
return content
301+
302+
303+
def get_scoped_connection(klass, scopes):
304+
"""Create a scoped connection to GCloud.
305+
306+
:type klass: type
307+
:param klass: the specific ``Connection`` class to instantiate.
308+
309+
:type scopes: list of URLs
310+
:param scopes: the effective service auth scopes for the connection.
311+
312+
:rtype: instance of ``klass``
313+
:returns: A connection defined with the proper credentials.
314+
"""
315+
implicit_credentials = get_credentials()
316+
scoped_credentials = implicit_credentials.create_scoped(scopes)
317+
return klass(credentials=scoped_credentials)

gcloud/datastore/_implicit_environ.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from gcloud._helpers import _app_engine_id
2424
from gcloud._helpers import _compute_engine_id
2525
from gcloud._helpers import _lazy_property_deco
26-
from gcloud._helpers import get_scoped_connection
26+
from gcloud.connection import get_scoped_connection
2727
from gcloud.datastore.connection import Connection
2828

2929

gcloud/storage/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
import os
4242

4343
from gcloud import credentials
44-
from gcloud._helpers import get_scoped_connection
4544
from gcloud._helpers import get_default_project
4645
from gcloud._helpers import set_default_project
46+
from gcloud.connection import get_scoped_connection
4747
from gcloud.storage import _implicit_environ
4848
from gcloud.storage._implicit_environ import get_default_bucket
4949
from gcloud.storage._implicit_environ import get_default_connection

gcloud/test__helpers.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -302,34 +302,6 @@ def test_descriptor_for_project(self):
302302
self.assertTrue('project' in _helpers._DEFAULTS.__dict__)
303303

304304

305-
class Test_get_scoped_connection(unittest2.TestCase):
306-
307-
def _callFUT(self, klass, scopes):
308-
from gcloud._helpers import get_scoped_connection
309-
return get_scoped_connection(klass, scopes)
310-
311-
def test_it(self):
312-
from gcloud import credentials
313-
from gcloud.test_credentials import _Client
314-
from gcloud._testing import _Monkey
315-
316-
class _Connection(object):
317-
def __init__(self, credentials):
318-
self._credentials = credentials
319-
320-
SCOPES = ('https://www.googleapis.com/auth/example',
321-
'https://www.googleapis.com/auth/userinfo.email')
322-
323-
client = _Client()
324-
with _Monkey(credentials, client=client):
325-
found = self._callFUT(_Connection, SCOPES)
326-
327-
self.assertTrue(isinstance(found, _Connection))
328-
self.assertTrue(found._credentials is client._signed)
329-
self.assertEqual(found._credentials._scopes, SCOPES)
330-
self.assertTrue(client._get_app_default_called)
331-
332-
333305
class _AppIdentity(object):
334306

335307
def __init__(self, app_id):

gcloud/test_connection.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,31 @@ def __init__(self, headers, content):
347347
def request(self, **kw):
348348
self._called_with = kw
349349
return self._response, self._content
350+
351+
352+
class Test_get_scoped_connection(unittest2.TestCase):
353+
354+
def _callFUT(self, klass, scopes):
355+
from gcloud.connection import get_scoped_connection
356+
return get_scoped_connection(klass, scopes)
357+
358+
def test_it(self):
359+
from gcloud import credentials
360+
from gcloud.test_credentials import _Client
361+
from gcloud._testing import _Monkey
362+
363+
class _Connection(object):
364+
def __init__(self, credentials):
365+
self._credentials = credentials
366+
367+
SCOPES = ('https://www.googleapis.com/auth/example',
368+
'https://www.googleapis.com/auth/userinfo.email')
369+
370+
client = _Client()
371+
with _Monkey(credentials, client=client):
372+
found = self._callFUT(_Connection, SCOPES)
373+
374+
self.assertTrue(isinstance(found, _Connection))
375+
self.assertTrue(found._credentials is client._signed)
376+
self.assertEqual(found._credentials._scopes, SCOPES)
377+
self.assertTrue(client._get_app_default_called)

0 commit comments

Comments
 (0)