Skip to content

Commit

Permalink
Merge pull request #10 from onna/signed-url-creds
Browse files Browse the repository at this point in the history
Optionally specify alternative credentials when generating signed URLs.
  • Loading branch information
j-durbin authored Mar 8, 2023
2 parents 07af04f + ae258d3 commit fed1f60
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions guillotina_gcloudstorage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,17 @@ async def iterate_bucket_page(self, page_token=None, prefix=None):
data = await resp.json()
return data

async def generate_download_signed_url(self, key, expiration=timedelta(minutes=30)):
async def generate_download_signed_url(
self, key, expiration=timedelta(minutes=30), credentials=None
):
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"
)
request_args = {
"version": "v4",
"expiration": expiration,
"method": "GET",
}
if credentials:
request_args["credentials"] = credentials
return blob.generate_signed_url(**request_args)

0 comments on commit fed1f60

Please sign in to comment.