Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GCloud parameters as kwargs for storage.url #1193

Merged
merged 1 commit into from Nov 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 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 @@ -316,16 +316,19 @@ def url(self, name):
storage_base_url=self.custom_endpoint,
quoted_name=_quote(name, safe=b"/~"),
)
elif not self.custom_endpoint:
return blob.generate_signed_url(
expiration=self.expiration, version="v4"
)
else:
return blob.generate_signed_url(
bucket_bound_hostname=self.custom_endpoint,
expiration=self.expiration,
version="v4",
)
default_params = {
"bucket_bound_hostname": self.custom_endpoint,
"expiration": self.expiration,
"version": "v4",
}
params = parameters or {}

for key, value in default_params.items():
if value and key not in params:
params[key] = value

return blob.generate_signed_url(**params)

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