From 50763f6bf062b38d0eb9790727ee5e62760df8b0 Mon Sep 17 00:00:00 2001 From: Jon Durbin Date: Wed, 15 Feb 2023 08:53:42 -0500 Subject: [PATCH 1/3] Configurable prefix for paginated bucket list. --- CHANGELOG.rst | 6 ++++++ VERSION | 2 +- guillotina_gcloudstorage/storage.py | 5 +++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ce416cb..30e9611 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,9 @@ +6.0.5 (unreleased) +------------------ + +- Configurable prefix in `iterate_bucket_page` method + [j-durbin] + 6.0.4 (unreleased) ------------------ diff --git a/VERSION b/VERSION index 1aa5e41..288b2cd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.0.4 +6.0.5 diff --git a/guillotina_gcloudstorage/storage.py b/guillotina_gcloudstorage/storage.py index 5aecf6b..f549474 100644 --- a/guillotina_gcloudstorage/storage.py +++ b/guillotina_gcloudstorage/storage.py @@ -540,10 +540,11 @@ async def iterate_bucket(self): yield item page_token = data.get("nextPageToken") - async def iterate_bucket_page(self, page_token=None): + async def iterate_bucket_page(self, page_token=None, prefix=None): url = "{}/{}/o".format(OBJECT_BASE_URL, await self.get_bucket_name()) container = task_vars.container.get() - params = {"prefix": container.id + "/"} + prefix = prefix or container.id + "/" + params = {"prefix": prefix} if page_token: params["pageToken"] = page_token From 664e213f4117e04c072cd6f2a3b80de275fb2ca2 Mon Sep 17 00:00:00 2001 From: Jon Durbin Date: Wed, 15 Feb 2023 08:55:27 -0500 Subject: [PATCH 2/3] New black formatting. --- guillotina_gcloudstorage/storage.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/guillotina_gcloudstorage/storage.py b/guillotina_gcloudstorage/storage.py index f549474..501695b 100644 --- a/guillotina_gcloudstorage/storage.py +++ b/guillotina_gcloudstorage/storage.py @@ -50,7 +50,9 @@ class IGCloudFileStorageManager(IExternalFileStorageManager): MAX_SIZE = 1073741824 SCOPES = ["https://www.googleapis.com/auth/devstorage.read_write"] -UPLOAD_URL = "https://www.googleapis.com/upload/storage/v1/b/{bucket}/o?uploadType=resumable" # noqa +UPLOAD_URL = ( + "https://www.googleapis.com/upload/storage/v1/b/{bucket}/o?uploadType=resumable" +) # noqa OBJECT_BASE_URL = "https://www.googleapis.com/storage/v1/b" CHUNK_SIZE = 524288 MAX_RETRIES = 5 @@ -431,10 +433,8 @@ async def get_access_token(self): def get_client(self): if self._client is None: - self._client = ( - google.cloud.storage.Client.from_service_account_json( # noqa - self._json_credentials - ) + self._client = google.cloud.storage.Client.from_service_account_json( # noqa + self._json_credentials ) return self._client From b10b756cd1d31897c97c8229fc62d39dcecee019 Mon Sep 17 00:00:00 2001 From: Jon Durbin Date: Wed, 15 Feb 2023 08:56:55 -0500 Subject: [PATCH 3/3] New black formatting. --- guillotina_gcloudstorage/storage.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/guillotina_gcloudstorage/storage.py b/guillotina_gcloudstorage/storage.py index 501695b..f459ac9 100644 --- a/guillotina_gcloudstorage/storage.py +++ b/guillotina_gcloudstorage/storage.py @@ -50,9 +50,7 @@ class IGCloudFileStorageManager(IExternalFileStorageManager): MAX_SIZE = 1073741824 SCOPES = ["https://www.googleapis.com/auth/devstorage.read_write"] -UPLOAD_URL = ( - "https://www.googleapis.com/upload/storage/v1/b/{bucket}/o?uploadType=resumable" -) # noqa +UPLOAD_URL = "https://www.googleapis.com/upload/storage/v1/b/{bucket}/o?uploadType=resumable" # noqa OBJECT_BASE_URL = "https://www.googleapis.com/storage/v1/b" CHUNK_SIZE = 524288 MAX_RETRIES = 5 @@ -88,7 +86,6 @@ def _is_uploaded_file(file): for_=(IResource, IRequest, IGCloudFileField), provides=IGCloudFileStorageManager ) class GCloudFileManager(object): - file_class = GCloudFile def __init__(self, context, request, field): @@ -433,8 +430,10 @@ async def get_access_token(self): def get_client(self): if self._client is None: - self._client = google.cloud.storage.Client.from_service_account_json( # noqa - self._json_credentials + self._client = ( + google.cloud.storage.Client.from_service_account_json( # noqa + self._json_credentials + ) ) return self._client