Skip to content

Commit a32a022

Browse files
committed
Changing datastore Connection to only accept client.
1 parent 1efdb00 commit a32a022

6 files changed

Lines changed: 92 additions & 104 deletions

File tree

core/google/cloud/_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Connection(object):
3636
"""A generic connection to Google Cloud Platform.
3737
3838
:type client: :class:`~google.cloud.client.Client`
39-
:param client: The client that owns the credentials.
39+
:param client: The client that owns the current connection.
4040
"""
4141

4242
USER_AGENT = DEFAULT_USER_AGENT

core/google/cloud/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class Client(_ClientFactoryMixin):
109109
``credentials`` for the current object.
110110
"""
111111

112-
_SCOPE = None
112+
SCOPE = None
113113
"""The scopes required for authenticating with a service.
114114
115115
Needs to be set by subclasses.
@@ -123,7 +123,7 @@ def __init__(self, credentials=None, http=None):
123123
if credentials is None and http is None:
124124
credentials = get_credentials()
125125
self._credentials = google.auth.credentials.with_scopes_if_required(
126-
credentials, self._SCOPE)
126+
credentials, self.SCOPE)
127127
self._http_internal = http
128128

129129
@property

datastore/google/cloud/datastore/_http.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,8 @@ class Connection(connection_module.Connection):
397397
in method arguments, however it should be capable of returning advanced
398398
types.
399399
400-
:type credentials: :class:`oauth2client.client.OAuth2Credentials`
401-
:param credentials: The OAuth2 Credentials to use for this connection.
402-
403-
:type http: :class:`httplib2.Http` or class that defines ``request()``.
404-
:param http: An optional HTTP object to make requests.
400+
:type client: :class:`~google.cloud.datastore.client.Client`
401+
:param client: The client that owns the current connection.
405402
"""
406403

407404
API_BASE_URL = 'https://' + DATASTORE_API_HOST
@@ -414,11 +411,8 @@ class Connection(connection_module.Connection):
414411
'/{project}:{method}')
415412
"""A template for the URL of a particular API call."""
416413

417-
SCOPE = ('https://www.googleapis.com/auth/datastore',)
418-
"""The scopes required for authenticating as a Cloud Datastore consumer."""
419-
420-
def __init__(self, credentials=None, http=None):
421-
super(Connection, self).__init__(credentials=credentials, http=http)
414+
def __init__(self, client):
415+
super(Connection, self).__init__(client)
422416
try:
423417
self.host = os.environ[GCD_HOST]
424418
self.api_base_url = 'http://' + self.host

datastore/google/cloud/datastore/client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
from google.cloud._helpers import _LocalStack
1919
from google.cloud._helpers import (
2020
_determine_default_project as _base_default_project)
21-
from google.cloud.client import _ClientProjectMixin
22-
from google.cloud.client import Client as _BaseClient
21+
from google.cloud.client import ClientWithProject
2322
from google.cloud.datastore._http import Connection
2423
from google.cloud.datastore import helpers
2524
from google.cloud.datastore.batch import Batch
@@ -143,7 +142,7 @@ def _extended_lookup(connection, project, key_pbs,
143142
return results
144143

145144

146-
class Client(_BaseClient, _ClientProjectMixin):
145+
class Client(ClientWithProject):
147146
"""Convenience wrapper for invoking APIs/factories w/ a project.
148147
149148
.. doctest::
@@ -171,13 +170,14 @@ class Client(_BaseClient, _ClientProjectMixin):
171170
``credentials`` for the current object.
172171
"""
173172

173+
SCOPE = ('https://www.googleapis.com/auth/datastore',)
174+
"""The scopes required for authenticating as a Cloud Datastore consumer."""
175+
174176
def __init__(self, project=None, namespace=None,
175177
credentials=None, http=None):
176-
_ClientProjectMixin.__init__(self, project=project)
177-
_BaseClient.__init__(self, credentials=credentials, http=http)
178-
self._connection = Connection(
179-
credentials=self._credentials, http=self._http)
180-
178+
super(Client, self).__init__(
179+
project=project, credentials=credentials, http=http)
180+
self._connection = Connection(self)
181181
self.namespace = namespace
182182
self._batch_stack = _LocalStack()
183183

0 commit comments

Comments
 (0)