From b4146a9a394dfdc7d1bf41426761f98ab4d5453a Mon Sep 17 00:00:00 2001 From: Jack Michaud Date: Wed, 6 Apr 2022 13:51:14 -0700 Subject: [PATCH 1/4] fix: support setting STORAGE_EMULATOR_HOST without /storage/{version} suffix --- google/cloud/storage/_http.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/google/cloud/storage/_http.py b/google/cloud/storage/_http.py index 0ade1525f..8eaee23c0 100644 --- a/google/cloud/storage/_http.py +++ b/google/cloud/storage/_http.py @@ -39,7 +39,15 @@ class Connection(_http.JSONConnection): def __init__(self, client, client_info=None, api_endpoint=None): super(Connection, self).__init__(client, client_info) - self.API_BASE_URL = api_endpoint or self.DEFAULT_API_ENDPOINT + self.API_BASE_URL = ( + api_endpoint or self.DEFAULT_API_ENDPOINT + "/storage/{self.API_VERSION}" + ) + # A template for the URL of a particular API call. + self.API_URL_TEMPLATE = ( + "{api_base_url}/storage/{api_version}{path}" + if api_endpoint is None + else "{api_base_url}{path}" + ) self.API_BASE_MTLS_URL = self.DEFAULT_API_MTLS_ENDPOINT self.ALLOW_AUTO_SWITCH_TO_MTLS_URL = api_endpoint is None self._client_info.client_library_version = __version__ @@ -54,9 +62,6 @@ def __init__(self, client, client_info=None, api_endpoint=None): API_VERSION = "v1" """The version of the API, used in building the API call's URL.""" - API_URL_TEMPLATE = "{api_base_url}/storage/{api_version}{path}" - """A template for the URL of a particular API call.""" - def api_request(self, *args, **kwargs): retry = kwargs.pop("retry", None) call = functools.partial(super(Connection, self).api_request, *args, **kwargs) From bd075c8a7d9a9b9fb12a110938bbc2dc81b1f81b Mon Sep 17 00:00:00 2001 From: Jack Michaud Date: Fri, 8 Apr 2022 13:01:06 -0700 Subject: [PATCH 2/4] fix: add name to query parameters for blob upload --- google/cloud/storage/blob.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/google/cloud/storage/blob.py b/google/cloud/storage/blob.py index a4e1d402d..6e4a58450 100644 --- a/google/cloud/storage/blob.py +++ b/google/cloud/storage/blob.py @@ -1876,6 +1876,9 @@ def _do_multipart_upload( if self.user_project is not None: name_value_pairs.append(("userProject", self.user_project)) + if self.name is not None: + name_value_pairs.append(("name", self.name)) + # When a Customer Managed Encryption Key is used to encrypt Cloud Storage object # at rest, object resource metadata will store the version of the Key Management # Service cryptographic material. If a Blob instance with KMS Key metadata set is From 922ba5df52356b756ec831eec1df458dc07b58b2 Mon Sep 17 00:00:00 2001 From: Jack Michaud Date: Wed, 13 Apr 2022 10:17:45 -0700 Subject: [PATCH 3/4] fix: add name to resumable uploads --- google/cloud/storage/blob.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/google/cloud/storage/blob.py b/google/cloud/storage/blob.py index 6e4a58450..79df38329 100644 --- a/google/cloud/storage/blob.py +++ b/google/cloud/storage/blob.py @@ -2066,6 +2066,9 @@ def _initiate_resumable_upload( if self.user_project is not None: name_value_pairs.append(("userProject", self.user_project)) + if self.name is not None: + name_value_pairs.append(("name", self.name)) + # When a Customer Managed Encryption Key is used to encrypt Cloud Storage object # at rest, object resource metadata will store the version of the Key Management # Service cryptographic material. If a Blob instance with KMS Key metadata set is From 99e15b9a676eebc05774ac941fe30f27c54975d5 Mon Sep 17 00:00:00 2001 From: Jack Michaud Date: Wed, 13 Apr 2022 10:20:43 -0700 Subject: [PATCH 4/4] Revert "fix: support setting STORAGE_EMULATOR_HOST without /storage/{version} suffix" This reverts commit b4146a9a394dfdc7d1bf41426761f98ab4d5453a. --- google/cloud/storage/_http.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/google/cloud/storage/_http.py b/google/cloud/storage/_http.py index 29aa716f3..9b29f6280 100644 --- a/google/cloud/storage/_http.py +++ b/google/cloud/storage/_http.py @@ -40,15 +40,7 @@ class Connection(_http.JSONConnection): def __init__(self, client, client_info=None, api_endpoint=None): super(Connection, self).__init__(client, client_info) - self.API_BASE_URL = ( - api_endpoint or self.DEFAULT_API_ENDPOINT + "/storage/{self.API_VERSION}" - ) - # A template for the URL of a particular API call. - self.API_URL_TEMPLATE = ( - "{api_base_url}/storage/{api_version}{path}" - if api_endpoint is None - else "{api_base_url}{path}" - ) + self.API_BASE_URL = api_endpoint or self.DEFAULT_API_ENDPOINT self.API_BASE_MTLS_URL = self.DEFAULT_API_MTLS_ENDPOINT self.ALLOW_AUTO_SWITCH_TO_MTLS_URL = api_endpoint is None self._client_info.client_library_version = __version__ @@ -63,6 +55,9 @@ def __init__(self, client, client_info=None, api_endpoint=None): API_VERSION = "v1" """The version of the API, used in building the API call's URL.""" + API_URL_TEMPLATE = "{api_base_url}/storage/{api_version}{path}" + """A template for the URL of a particular API call.""" + def api_request(self, *args, **kwargs): retry = kwargs.pop("retry", None) kwargs["extra_api_info"] = _helpers._get_invocation_id()