Skip to content

Commit

Permalink
Add GCloud parameters as kwargs for storage.url
Browse files Browse the repository at this point in the history
  • Loading branch information
fao89 committed Nov 1, 2022
1 parent f0df471 commit 6a0c423
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions storages/backends/gcloud.py
Expand Up @@ -297,7 +297,7 @@ def get_created_time(self, name):
created = blob.time_created
return created if setting('USE_TZ') else timezone.make_naive(created)

def url(self, name):
def url(self, name, parameters=None):
"""
Return public url or a signed url for the Blob.
This DOES NOT check for existance of Blob - that makes codes too slow
Expand All @@ -309,6 +309,8 @@ def url(self, name):
no_signed_url = (
blob_params.get('acl', self.default_acl) == 'publicRead' or not self.querystring_auth)

params = parameters or {"expiration": self.expiration, "version": "v4"}

if not self.custom_endpoint and no_signed_url:
return blob.public_url
elif no_signed_url:
Expand All @@ -317,15 +319,11 @@ def url(self, name):
quoted_name=_quote(name, safe=b"/~"),
)
elif not self.custom_endpoint:
return blob.generate_signed_url(
expiration=self.expiration, version="v4"
)
return blob.generate_signed_url(**params)
else:
return blob.generate_signed_url(
bucket_bound_hostname=self.custom_endpoint,
expiration=self.expiration,
version="v4",
)
if "bucket_bound_hostname" not in params:
params["bucket_bound_hostname"] = self.custom_endpoint
return blob.generate_signed_url(**params)

def get_available_name(self, name, max_length=None):
name = clean_name(name)
Expand Down

0 comments on commit 6a0c423

Please sign in to comment.