From 7a08a2ce1e33531db962f73cf9cb4c605799cfa2 Mon Sep 17 00:00:00 2001 From: Kazuki Takamatsu Date: Mon, 10 Jun 2024 09:45:07 +0900 Subject: [PATCH 1/3] fix: google storage init with sa and download --- api/extensions/storage/google_storage.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/extensions/storage/google_storage.py b/api/extensions/storage/google_storage.py index 97004fddab20f6..b0051f4b14159c 100644 --- a/api/extensions/storage/google_storage.py +++ b/api/extensions/storage/google_storage.py @@ -1,4 +1,5 @@ import base64 +import json import io from collections.abc import Generator from contextlib import closing @@ -20,7 +21,8 @@ def __init__(self, app: Flask): # if service_account_json_str is empty, use Application Default Credentials if service_account_json_str: service_account_json = base64.b64decode(service_account_json_str).decode('utf-8') - self.client = GoogleCloudStorage.Client.from_service_account_info(service_account_json) + service_account_obj = json.loads(service_account_json) + self.client = GoogleCloudStorage.Client.from_service_account_info(service_account_obj) else: self.client = GoogleCloudStorage.Client() @@ -48,9 +50,7 @@ def generate(filename: str = filename) -> Generator: def download(self, filename, target_filepath): bucket = self.client.get_bucket(self.bucket_name) blob = bucket.get_blob(filename) - with open(target_filepath, "wb") as my_blob: - blob_data = blob.download_blob() - blob_data.readinto(my_blob) + blob.download_to_filename(target_filepath) def exists(self, filename): bucket = self.client.get_bucket(self.bucket_name) From bb37a9946a604337505e679b8cdbb55299c2a29a Mon Sep 17 00:00:00 2001 From: Kazuki Takamatsu Date: Mon, 10 Jun 2024 10:16:45 +0900 Subject: [PATCH 2/3] fix with dev/reformat --- api/extensions/storage/google_storage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/extensions/storage/google_storage.py b/api/extensions/storage/google_storage.py index b0051f4b14159c..9370a0788a9bc6 100644 --- a/api/extensions/storage/google_storage.py +++ b/api/extensions/storage/google_storage.py @@ -1,6 +1,6 @@ import base64 -import json import io +import json from collections.abc import Generator from contextlib import closing From 583cfc57606483c88e7485e9ee65d88ffcc738df Mon Sep 17 00:00:00 2001 From: Kazuki Takamatsu Date: Mon, 10 Jun 2024 10:19:12 +0900 Subject: [PATCH 3/3] fix: add comment --- api/extensions/storage/google_storage.py | 1 + 1 file changed, 1 insertion(+) diff --git a/api/extensions/storage/google_storage.py b/api/extensions/storage/google_storage.py index 9370a0788a9bc6..ef6cd69039787c 100644 --- a/api/extensions/storage/google_storage.py +++ b/api/extensions/storage/google_storage.py @@ -21,6 +21,7 @@ def __init__(self, app: Flask): # if service_account_json_str is empty, use Application Default Credentials if service_account_json_str: service_account_json = base64.b64decode(service_account_json_str).decode('utf-8') + # convert str to object service_account_obj = json.loads(service_account_json) self.client = GoogleCloudStorage.Client.from_service_account_info(service_account_obj) else: