fix(storage): anonymous credentials for private bucket#107
fix(storage): anonymous credentials for private bucket#107frankyn merged 12 commits intogoogleapis:masterfrom
Conversation
frankyn
left a comment
There was a problem hiding this comment.
Thanks @HemangChothani left some comments.
google/cloud/storage/client.py
Outdated
| if client_options.api_endpoint: | ||
| api_endpoint = client_options.api_endpoint | ||
| kw_args["api_endpoint"] = api_endpoint | ||
| _override_private_url_variables(api_endpoint) |
There was a problem hiding this comment.
Thanks for putting this together. I think the code needs to be refactored for maintainability but the this is a good start.
The URLs in URL Templates could be refactored to be pulled in from the client which is passed around the library.
For example:
python-storage/google/cloud/storage/blob.py
Line 1020 in a50cdd1
Could be updated to:
_BASE_UPLOAD_TEMPLATE = u"{hostname}/upload/storage/v1{bucket_path}/o?uploadType="
_MULTIPART_URL_TEMPLATE = _BASE_UPLOAD_TEMPLATE + u"multipart"
# truncated....
base_url = _MULTIPART_URL_TEMPLATE.format(hostname=storage_client._connection.API_BASE_URL,bucket_path=self.bucket.path)
WDYT?
google/cloud/storage/client.py
Outdated
| blob._API_ACCESS_ENDPOINT = api_endpoint | ||
| bucket._API_ACCESS_ENDPOINT = api_endpoint |
There was a problem hiding this comment.
These URLs are used for Signature based requests like Signed URLs. These can be left alone because the method has a way to update the hostname because they don't use the same API (Download and Upload use JSON while Signature requests use XML API).
|
@frankyn still we can refactor, need your suggestion.
OR
|
frankyn
left a comment
There was a problem hiding this comment.
Let's keep it the way you have it with one minor nit. This looks much better than before.
Thanks @HemangChothani
| return client._http | ||
|
|
||
| def _get_download_url(self): | ||
| def _get_download_url(self, client): |
There was a problem hiding this comment.
Instead of this could you use client() that's already available here: https://github.com/googleapis/python-storage/pull/107/files#diff-5d3277a5f0f072a447a1eb89f9fa1ae0R273-R275
There was a problem hiding this comment.
this was a bad call, you'll need to do this along with _require_client() otherwise you can end up in a bad state.
There was a problem hiding this comment.
_require_client() has been call by _get_transport method so moving _get_download_url method call after that.
One system test has failed so fixed that.
…into storage_issue_102
frankyn
left a comment
There was a problem hiding this comment.
1 more question. Thanks for fixing this @HemangChothani!
google/cloud/storage/client.py
Outdated
| blob_or_uri.download_to_file(file_obj, client=self, start=start, end=end) | ||
| except AttributeError: | ||
| blob = Blob.from_string(blob_or_uri) | ||
| blob = Blob.from_string(blob_or_uri, client=self) |
There was a problem hiding this comment.
was this an accidental miss in implementation? Seems like it but want to confirm.
There was a problem hiding this comment.
Looking at it again, client is passed below to download_to_file(). The change doesn't look necessary.
There was a problem hiding this comment.
Yes, but the problem arise here , if i didn't pass the client so bucket class has received None
python-storage/google/cloud/storage/blob.py
Line 351 in 18b1e07
so when call _require_client() method it find the client object which passed in download_to_file() so hostname=self.client._connection.API_BASE_URL line hit the error as self.client found None
There was a problem hiding this comment.
Gotcha, when I raised that you should revert my last comment, I was referring to updating the method _get_download_url() to accept client parameter because even though _get_transport calls _require_client() it doesn't update self.client with a value if it's None.
I think you may want to pass client returned from _require_client() to _get_download_url().
Thank you for your patience.
…into storage_issue_102
…-storage into storage_issue_102
frankyn
left a comment
There was a problem hiding this comment.
@HemangChothani pending tests passing, but LGTM
|
@HemangChothani asked @crwilcox to take another pass to confirm. |
* fix(storage): anonymous credentials for private bucket * fix(storage): use API_BASE_URL for hostname * fix(storage): nit * fix(storage): fix system test * fix(storage): revert changes Co-authored-by: Frank Natividad <frankyn@users.noreply.github.com>
* fix(storage): anonymous credentials for private bucket * fix(storage): use API_BASE_URL for hostname * fix(storage): nit * fix(storage): fix system test * fix(storage): revert changes Co-authored-by: Frank Natividad <frankyn@users.noreply.github.com>
Fixes #102
We can override the private variables of blob class related to api_endpoint, upload_uri, download_uri.
Still confusion with these two parameters: