Skip to content

Commit

Permalink
Rolling back all storage changes aside from #4133 and #4180.
Browse files Browse the repository at this point in the history
Had to make a few small manual tweaks as well.
  • Loading branch information
dhermes committed Oct 13, 2017
1 parent 448b147 commit 95ab8a5
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 2,473 deletions.
17 changes: 2 additions & 15 deletions storage/google/cloud/storage/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ def client(self):
"""Abstract getter for the object client."""
raise NotImplementedError

@property
def user_project(self):
"""Abstract getter for the object user_project."""
raise NotImplementedError

def _require_client(self, client):
"""Check client or verify over-ride.
Expand Down Expand Up @@ -99,8 +94,6 @@ def reload(self, client=None):
# Pass only '?projection=noAcl' here because 'acl' and related
# are handled via custom endpoints.
query_params = {'projection': 'noAcl'}
if self.user_project is not None:
query_params['userProject'] = self.user_project
api_response = client._connection.api_request(
method='GET', path=self.path, query_params=query_params,
_target_object=self)
Expand Down Expand Up @@ -147,16 +140,13 @@ def patch(self, client=None):
client = self._require_client(client)
# Pass '?projection=full' here because 'PATCH' documented not
# to work properly w/ 'noAcl'.
query_params = {'projection': 'full'}
if self.user_project is not None:
query_params['userProject'] = self.user_project
update_properties = {key: self._properties[key]
for key in self._changes}

# Make the API call.
api_response = client._connection.api_request(
method='PATCH', path=self.path, data=update_properties,
query_params=query_params, _target_object=self)
query_params={'projection': 'full'}, _target_object=self)
self._set_properties(api_response)

def update(self, client=None):
Expand All @@ -170,12 +160,9 @@ def update(self, client=None):
``client`` stored on the current object.
"""
client = self._require_client(client)
query_params = {'projection': 'full'}
if self.user_project is not None:
query_params['userProject'] = self.user_project
api_response = client._connection.api_request(
method='PUT', path=self.path, data=self._properties,
query_params=query_params, _target_object=self)
query_params={'projection': 'full'}, _target_object=self)
self._set_properties(api_response)


Expand Down
25 changes: 1 addition & 24 deletions storage/google/cloud/storage/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ class ACL(object):
# as properties).
reload_path = None
save_path = None
user_project = None

def __init__(self):
self.entities = {}
Expand Down Expand Up @@ -406,18 +405,10 @@ def reload(self, client=None):
"""
path = self.reload_path
client = self._require_client(client)
query_params = {}

if self.user_project is not None:
query_params['userProject'] = self.user_project

self.entities.clear()

found = client._connection.api_request(
method='GET',
path=path,
query_params=query_params,
)
found = client._connection.api_request(method='GET', path=path)
self.loaded = True
for entry in found.get('items', ()):
self.add_entity(self.entity_from_dict(entry))
Expand All @@ -444,12 +435,8 @@ def _save(self, acl, predefined, client):
acl = []
query_params[self._PREDEFINED_QUERY_PARAM] = predefined

if self.user_project is not None:
query_params['userProject'] = self.user_project

path = self.save_path
client = self._require_client(client)

result = client._connection.api_request(
method='PATCH',
path=path,
Expand Down Expand Up @@ -545,11 +532,6 @@ def save_path(self):
"""Compute the path for PATCH API requests for this ACL."""
return self.bucket.path

@property
def user_project(self):
"""Compute the user project charged for API requests for this ACL."""
return self.bucket.user_project


class DefaultObjectACL(BucketACL):
"""A class representing the default object ACL for a bucket."""
Expand Down Expand Up @@ -583,8 +565,3 @@ def reload_path(self):
def save_path(self):
"""Compute the path for PATCH API requests for this ACL."""
return self.blob.path

@property
def user_project(self):
"""Compute the user project charged for API requests for this ACL."""
return self.blob.user_project
141 changes: 20 additions & 121 deletions storage/google/cloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@
import time
import warnings

from six.moves.urllib.parse import parse_qsl
from six.moves.urllib.parse import quote
from six.moves.urllib.parse import urlencode
from six.moves.urllib.parse import urlsplit
from six.moves.urllib.parse import urlunsplit

from google import resumable_media
from google.resumable_media.requests import ChunkedDownload
Expand Down Expand Up @@ -224,16 +220,6 @@ def client(self):
"""The client bound to this blob."""
return self.bucket.client

@property
def user_project(self):
"""Project ID used for API requests made via this blob.
Derived from bucket's value.
:rtype: str
"""
return self.bucket.user_project

@property
def public_url(self):
"""The public URL for this blob's object.
Expand Down Expand Up @@ -342,14 +328,10 @@ def exists(self, client=None):
:returns: True if the blob exists in Cloud Storage.
"""
client = self._require_client(client)
# We only need the status code (200 or not) so we seek to
# minimize the returned payload.
query_params = {'fields': 'name'}

if self.user_project is not None:
query_params['userProject'] = self.user_project

try:
# We only need the status code (200 or not) so we seek to
# minimize the returned payload.
query_params = {'fields': 'name'}
# We intentionally pass `_target_object=None` since fields=name
# would limit the local properties.
client._connection.api_request(
Expand Down Expand Up @@ -403,19 +385,13 @@ def _get_download_url(self):
:rtype: str
:returns: The download URL for the current blob.
"""
name_value_pairs = []
if self.media_link is None:
base_url = _DOWNLOAD_URL_TEMPLATE.format(path=self.path)
download_url = _DOWNLOAD_URL_TEMPLATE.format(path=self.path)
if self.generation is not None:
name_value_pairs.append(
('generation', '{:d}'.format(self.generation)))
download_url += u'&generation={:d}'.format(self.generation)
return download_url
else:
base_url = self.media_link

if self.user_project is not None:
name_value_pairs.append(('userProject', self.user_project))

return _add_query_parameters(base_url, name_value_pairs)
return self.media_link

def _do_download(self, transport, file_obj, download_url, headers):
"""Perform a download without any error handling.
Expand Down Expand Up @@ -482,9 +458,8 @@ def download_to_file(self, file_obj, client=None):
"""
download_url = self._get_download_url()
headers = _get_encryption_headers(self._encryption_key)
headers['accept-encoding'] = 'gzip'

transport = self._get_transport(client)

try:
self._do_download(transport, file_obj, download_url, headers)
except resumable_media.InvalidResponse as exc:
Expand Down Expand Up @@ -667,14 +642,8 @@ def _do_multipart_upload(self, client, stream, content_type,
info = self._get_upload_arguments(content_type)
headers, object_metadata, content_type = info

base_url = _MULTIPART_URL_TEMPLATE.format(
upload_url = _MULTIPART_URL_TEMPLATE.format(
bucket_path=self.bucket.path)
name_value_pairs = []

if self.user_project is not None:
name_value_pairs.append(('userProject', self.user_project))

upload_url = _add_query_parameters(base_url, name_value_pairs)
upload = MultipartUpload(upload_url, headers=headers)

if num_retries is not None:
Expand Down Expand Up @@ -745,14 +714,8 @@ def _initiate_resumable_upload(self, client, stream, content_type,
if extra_headers is not None:
headers.update(extra_headers)

base_url = _RESUMABLE_URL_TEMPLATE.format(
upload_url = _RESUMABLE_URL_TEMPLATE.format(
bucket_path=self.bucket.path)
name_value_pairs = []

if self.user_project is not None:
name_value_pairs.append(('userProject', self.user_project))

upload_url = _add_query_parameters(base_url, name_value_pairs)
upload = ResumableUpload(upload_url, chunk_size, headers=headers)

if num_retries is not None:
Expand Down Expand Up @@ -1106,16 +1069,9 @@ def get_iam_policy(self, client=None):
the ``getIamPolicy`` API request.
"""
client = self._require_client(client)

query_params = {}

if self.user_project is not None:
query_params['userProject'] = self.user_project

info = client._connection.api_request(
method='GET',
path='%s/iam' % (self.path,),
query_params=query_params,
_target_object=None)
return Policy.from_api_repr(info)

Expand All @@ -1138,18 +1094,11 @@ def set_iam_policy(self, policy, client=None):
the ``setIamPolicy`` API request.
"""
client = self._require_client(client)

query_params = {}

if self.user_project is not None:
query_params['userProject'] = self.user_project

resource = policy.to_api_repr()
resource['resourceId'] = self.path
info = client._connection.api_request(
method='PUT',
path='%s/iam' % (self.path,),
query_params=query_params,
data=resource,
_target_object=None)
return Policy.from_api_repr(info)
Expand All @@ -1173,17 +1122,12 @@ def test_iam_permissions(self, permissions, client=None):
request.
"""
client = self._require_client(client)
query_params = {'permissions': permissions}

if self.user_project is not None:
query_params['userProject'] = self.user_project

query = {'permissions': permissions}
path = '%s/iam/testPermissions' % (self.path,)
resp = client._connection.api_request(
method='GET',
path=path,
query_params=query_params)

query_params=query)
return resp.get('permissions', [])

def make_public(self, client=None):
Expand Down Expand Up @@ -1213,22 +1157,13 @@ def compose(self, sources, client=None):
"""
if self.content_type is None:
raise ValueError("Destination 'content_type' not set.")

client = self._require_client(client)
query_params = {}

if self.user_project is not None:
query_params['userProject'] = self.user_project

request = {
'sourceObjects': [{'name': source.name} for source in sources],
'destination': self._properties.copy(),
}
api_response = client._connection.api_request(
method='POST',
path=self.path + '/compose',
query_params=query_params,
data=request,
method='POST', path=self.path + '/compose', data=request,
_target_object=self)
self._set_properties(api_response)

Expand Down Expand Up @@ -1260,20 +1195,14 @@ def rewrite(self, source, token=None, client=None):
headers.update(_get_encryption_headers(
source._encryption_key, source=True))

query_params = {}

if token:
query_params['rewriteToken'] = token

if self.user_project is not None:
query_params['userProject'] = self.user_project
query_params = {'rewriteToken': token}
else:
query_params = {}

api_response = client._connection.api_request(
method='POST',
path=source.path + '/rewriteTo' + self.path,
query_params=query_params,
data=self._properties,
headers=headers,
method='POST', path=source.path + '/rewriteTo' + self.path,
query_params=query_params, data=self._properties, headers=headers,
_target_object=self)
rewritten = int(api_response['totalBytesRewritten'])
size = int(api_response['objectSize'])
Expand Down Expand Up @@ -1304,22 +1233,13 @@ def update_storage_class(self, new_class, client=None):
raise ValueError("Invalid storage class: %s" % (new_class,))

client = self._require_client(client)

query_params = {}

if self.user_project is not None:
query_params['userProject'] = self.user_project

headers = _get_encryption_headers(self._encryption_key)
headers.update(_get_encryption_headers(
self._encryption_key, source=True))

api_response = client._connection.api_request(
method='POST',
path=self.path + '/rewriteTo' + self.path,
query_params=query_params,
data={'storageClass': new_class},
headers=headers,
method='POST', path=self.path + '/rewriteTo' + self.path,
data={'storageClass': new_class}, headers=headers,
_target_object=self)
self._set_properties(api_response['resource'])

Expand Down Expand Up @@ -1688,24 +1608,3 @@ def _raise_from_invalid_response(error):
to the failed status code
"""
raise exceptions.from_http_response(error.response)


def _add_query_parameters(base_url, name_value_pairs):
"""Add one query parameter to a base URL.
:type base_url: string
:param base_url: Base URL (may already contain query parameters)
:type name_value_pairs: list of (string, string) tuples.
:param name_value_pairs: Names and values of the query parameters to add
:rtype: string
:returns: URL with additional query strings appended.
"""
if len(name_value_pairs) == 0:
return base_url

scheme, netloc, path, query, frag = urlsplit(base_url)
query = parse_qsl(query)
query.extend(name_value_pairs)
return urlunsplit((scheme, netloc, path, urlencode(query), frag))
Loading

0 comments on commit 95ab8a5

Please sign in to comment.