Skip to content

Commit

Permalink
Merge pull request #9 from onna/signed-url
Browse files Browse the repository at this point in the history
Method to generate signed download URLs
  • Loading branch information
j-durbin authored Mar 6, 2023
2 parents 6fe4deb + af05539 commit 07af04f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.6
6.0.7
9 changes: 9 additions & 0 deletions guillotina_gcloudstorage/storage.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
)

0 comments on commit 07af04f

Please sign in to comment.