-
Notifications
You must be signed in to change notification settings - Fork 39
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
Help with signed URLs #128
Comments
I started investigating this a bit. I was testing with the Python package The legacy version "v2" (or if the version is omitted) urls
The newer "v4" urls
The version shouldn't matter with the emulator since we're just ignoring those parameters at the moment. Looks like the signed urls are used only from the XML API, not from the JSON API. Those need to be added to the the supported URL endpoints, but that shouldn't be too time consuming. https://cloud.google.com/storage/docs/request-endpoints#xml-api Back to your first point. Could you pass |
Uploading with signed URLs is supported now. gcp-storage-emulator/tests/test_server.py Lines 797 to 838 in 646ea0c
|
I took a quick look at your code. Maybe you could use something like this, which is very easy to test by just passing the endpoint as an argument. def url(self, name, api_access_endpoint="https://storage.googleapis.com"):
name = safe_join(self.bucket_subdir, name)
name = prepare_name(name)
if self.use_unsigned_urls:
return "{}/{}/{}".format(api_access_endpoint, self.bucket.name, name)
return self.bucket.get_blob(name).generate_signed_url(api_access_endpoint=api_access_endpoint, expiration=datetime.datetime.now() + datetime.timedelta(hours=1)) Or maybe even as an argument to |
Thank you so much for looking into this so quickly! Also thanks for extending the code to support the XML API - fun to see the quick hack I did for signing credentials here :D I will most likely do something comparable to what you proposed for my I'll report back when I had time to try the new version. |
I'm going to close this, but feel free to open another ticket if you encounter other issues. |
Hi!
I'm trying to utilize gcp-storage-emulator for automated testing in https://github.com/strayer/django-gcloud-storage.
The basics are working, but two tests that are calling
bucket.get_blob(name).generate_signed_url
have issues… I built a fake credentials object that pretends to be able to sign:This makes the generate_signed_url function work in general. The returned URLs are problematic in two ways:
the host seems to be hardcoded to
https://storage.googleapis.com
in the SDK itself [see 1] – nothing gcp-storage-emulator can to about thatthe path is not generated in a way gcp-storage emulator expects:
GET /download/storage/v1/b/test_bucket_zdkgfs/test.jpg?Expires=1643405203&GoogleAccessId=foobar%40example.tld&Signature=Zm9vYmFy HTTP/1.1" 404 -
What is missing here is
/o/
before the filename.I've got my tests working by a very ugly hack to at least confirm some kind of working state by hacking the URLs returned by generate_signed_url:
Even though this is really ugly I can at least finally get automated tests without actual GCS access working, but I'm curious if I'm just missing something obvious here. Any help would be appreciated!
1: https://github.com/googleapis/python-storage/blob/main/google/cloud/storage/blob.py#L420
The text was updated successfully, but these errors were encountered: