Skip to content

Commit 111c7ef

Browse files
committed
Changing storage Connection to only accept client.
1 parent f651cce commit 111c7ef

File tree

6 files changed

+21
-27
lines changed

6 files changed

+21
-27
lines changed

storage/google/cloud/storage/_http.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@
2020
class Connection(_http.JSONConnection):
2121
"""A connection to Google Cloud Storage via the JSON REST API.
2222
23-
:type credentials: :class:`oauth2client.client.OAuth2Credentials`
24-
:param credentials: (Optional) The OAuth2 Credentials to use for this
25-
connection.
26-
27-
:type http: :class:`httplib2.Http` or class that defines ``request()``.
28-
:param http: (Optional) HTTP object to make requests.
23+
:type client: :class:`~google.cloud.storage.client.Client`
24+
:param client: The client that owns the current connection.
2925
"""
3026

3127
API_BASE_URL = _http.API_BASE_URL
@@ -36,8 +32,3 @@ class Connection(_http.JSONConnection):
3632

3733
API_URL_TEMPLATE = '{api_base_url}/storage/{api_version}{path}'
3834
"""A template for the URL of a particular API call."""
39-
40-
SCOPE = ('https://www.googleapis.com/auth/devstorage.full_control',
41-
'https://www.googleapis.com/auth/devstorage.read_only',
42-
'https://www.googleapis.com/auth/devstorage.read_write')
43-
"""The scopes required for authenticating as a Cloud Storage consumer."""

storage/google/cloud/storage/batch.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ class Batch(Connection):
132132
_MAX_BATCH_SIZE = 1000
133133

134134
def __init__(self, client):
135-
super(Batch, self).__init__()
136-
self._client = client
135+
super(Batch, self).__init__(client)
137136
self._requests = []
138137
self._target_objects = []
139138

storage/google/cloud/storage/client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ class Client(ClientWithProject):
4646
``credentials`` for the current object.
4747
"""
4848

49+
SCOPE = ('https://www.googleapis.com/auth/devstorage.full_control',
50+
'https://www.googleapis.com/auth/devstorage.read_only',
51+
'https://www.googleapis.com/auth/devstorage.read_write')
52+
"""The scopes required for authenticating as a Cloud Storage consumer."""
53+
4954
def __init__(self, project=None, credentials=None, http=None):
5055
self._base_connection = None
5156
super(Client, self).__init__(project=project, credentials=credentials,
5257
http=http)
53-
self._connection = Connection(
54-
credentials=self._credentials, http=self._http)
58+
self._connection = Connection(self)
5559
self._batch_stack = _LocalStack()
5660

5761
@property

storage/unit_tests/test__http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _make_one(self, *args, **kw):
2727
return self._get_target_class()(*args, **kw)
2828

2929
def test_build_api_url_no_extra_query_params(self):
30-
conn = self._make_one()
30+
conn = self._make_one(object())
3131
URI = '/'.join([
3232
conn.API_BASE_URL,
3333
'storage',
@@ -40,7 +40,7 @@ def test_build_api_url_w_extra_query_params(self):
4040
from six.moves.urllib.parse import parse_qsl
4141
from six.moves.urllib.parse import urlsplit
4242

43-
conn = self._make_one()
43+
conn = self._make_one(object())
4444
uri = conn.build_api_url('/foo', {'bar': 'baz'})
4545
scheme, netloc, path, qs, _ = urlsplit(uri)
4646
self.assertEqual('%s://%s' % (scheme, netloc), conn.API_BASE_URL)

storage/unit_tests/test_batch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def test_as_context_mgr_wo_error(self):
399399
project = 'PROJECT'
400400
credentials = _make_credentials()
401401
client = Client(project=project, credentials=credentials)
402-
client._base_connection._http = http
402+
client._http_internal = http
403403

404404
self.assertEqual(list(client._batch_stack), [])
405405

storage/unit_tests/test_client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_get_bucket_miss(self):
140140
'b',
141141
'nonesuch?projection=noAcl',
142142
])
143-
http = client._connection._http = _Http(
143+
http = client._http_internal = _Http(
144144
{'status': '404', 'content-type': 'application/json'},
145145
b'{}',
146146
)
@@ -163,7 +163,7 @@ def test_get_bucket_hit(self):
163163
'b',
164164
'%s?projection=noAcl' % (BLOB_NAME,),
165165
])
166-
http = client._connection._http = _Http(
166+
http = client._http_internal = _Http(
167167
{'status': '200', 'content-type': 'application/json'},
168168
'{{"name": "{0}"}}'.format(BLOB_NAME).encode('utf-8'),
169169
)
@@ -187,7 +187,7 @@ def test_lookup_bucket_miss(self):
187187
'b',
188188
'nonesuch?projection=noAcl',
189189
])
190-
http = client._connection._http = _Http(
190+
http = client._http_internal = _Http(
191191
{'status': '404', 'content-type': 'application/json'},
192192
b'{}',
193193
)
@@ -211,7 +211,7 @@ def test_lookup_bucket_hit(self):
211211
'b',
212212
'%s?projection=noAcl' % (BLOB_NAME,),
213213
])
214-
http = client._connection._http = _Http(
214+
http = client._http_internal = _Http(
215215
{'status': '200', 'content-type': 'application/json'},
216216
'{{"name": "{0}"}}'.format(BLOB_NAME).encode('utf-8'),
217217
)
@@ -236,7 +236,7 @@ def test_create_bucket_conflict(self):
236236
client._connection.API_VERSION,
237237
'b?project=%s' % (PROJECT,),
238238
])
239-
http = client._connection._http = _Http(
239+
http = client._http_internal = _Http(
240240
{'status': '409', 'content-type': 'application/json'},
241241
'{"error": {"message": "Conflict"}}',
242242
)
@@ -259,7 +259,7 @@ def test_create_bucket_success(self):
259259
client._connection.API_VERSION,
260260
'b?project=%s' % (PROJECT,),
261261
])
262-
http = client._connection._http = _Http(
262+
http = client._http_internal = _Http(
263263
{'status': '200', 'content-type': 'application/json'},
264264
'{{"name": "{0}"}}'.format(BLOB_NAME).encode('utf-8'),
265265
)
@@ -282,7 +282,7 @@ def test_list_buckets_empty(self):
282282
'project': [PROJECT],
283283
'projection': ['noAcl'],
284284
}
285-
http = client._connection._http = _Http(
285+
http = client._http_internal = _Http(
286286
{'status': '200', 'content-type': 'application/json'},
287287
b'{}',
288288
)
@@ -319,7 +319,7 @@ def test_list_buckets_non_empty(self):
319319
client._connection.API_VERSION,
320320
])
321321
URI = '/'.join([BASE_URI, 'b?%s' % (query_params,)])
322-
http = client._connection._http = _Http(
322+
http = client._http_internal = _Http(
323323
{'status': '200', 'content-type': 'application/json'},
324324
'{{"items": [{{"name": "{0}"}}]}}'.format(BUCKET_NAME)
325325
.encode('utf-8'),
@@ -354,7 +354,7 @@ def test_list_buckets_all_arguments(self):
354354
'fields': [FIELDS],
355355
}
356356

357-
http = client._connection._http = _Http(
357+
http = client._http_internal = _Http(
358358
{'status': '200', 'content-type': 'application/json'},
359359
'{"items": []}',
360360
)

0 commit comments

Comments
 (0)