diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 01b5c68..82ac558 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,7 @@ +6.0.7 (unreleased) +------------------ +- Method for generating signed download URLs + 6.0.6 (unreleased) ------------------ - Allow usage of Workload Identities for GCP authentication diff --git a/VERSION b/VERSION index b7ff151..089b1e6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.0.6 +6.0.7 diff --git a/guillotina_gcloudstorage/storage.py b/guillotina_gcloudstorage/storage.py index ebd993d..24803a3 100644 --- a/guillotina_gcloudstorage/storage.py +++ b/guillotina_gcloudstorage/storage.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from datetime import datetime +from datetime import timedelta from guillotina import configure from guillotina import task_vars from guillotina.component import get_multi_adapter @@ -589,3 +590,11 @@ async def iterate_bucket_page(self, page_token=None, prefix=None): assert resp.status == 200 data = await resp.json() return data + + async def generate_download_signed_url(self, key, expiration=timedelta(minutes=30)): + client = self.get_client() + bucket = google.cloud.storage.Bucket(client, name=await self.get_bucket_name()) + blob = bucket.blob(key) + return blob.generate_signed_url( + version="v4", expiration=expiration, method="GET" + )