Skip to content

Commit

Permalink
Add check for storage existence before creation in cache client
Browse files Browse the repository at this point in the history
  • Loading branch information
octonawish-akcodes committed Jul 26, 2023
1 parent 528df29 commit 08cbd22
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion kcidb/cache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,22 @@ def __init__(self, bucket_name, max_store_size):
"""
self.bucket_name = bucket_name
self.max_store_size = max_store_size
self.client = storage.Client()
self._create_bucket_if_not_exists(bucket_name)

def _bucket_exists(self, bucket_name):
"""Check if a GCS bucket exists."""
storage_client = storage.Client()
try:
storage_client.get_bucket(bucket_name)
return True
except Exception:
return False

def _create_bucket_if_not_exists(self, bucket_name):
"""Create a GCS bucket if it doesn't exist."""
if not self._bucket_exists(bucket_name):
storage_client = storage.Client()
storage_client.create_bucket(bucket_name)

@classmethod
def _extract_content_disposition(cls, response):
Expand Down

0 comments on commit 08cbd22

Please sign in to comment.