Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back out support for 'requester pays' buckets. #3538

Merged
merged 1 commit into from
Jun 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 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,14 +140,11 @@ 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}
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)


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
138 changes: 19 additions & 119 deletions storage/google/cloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@
import warnings

import httplib2
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

import google.auth.transport.requests
from google import resumable_media
Expand Down Expand Up @@ -226,16 +222,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 @@ -344,14 +330,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 @@ -407,19 +389,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 @@ -666,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 @@ -744,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 @@ -1105,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 @@ -1137,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 @@ -1172,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 @@ -1212,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 @@ -1259,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 @@ -1303,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 +1609,3 @@ def _raise_from_invalid_response(error, error_info=None):
faux_response = httplib2.Response({'status': response.status_code})
raise make_exception(faux_response, response.content,
error_info=error_info, use_json=False)


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