-
Notifications
You must be signed in to change notification settings - Fork 153
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
fix(storage): anonymous credentials for private bucket #107
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @HemangChothani left some comments.
google/cloud/storage/client.py
Outdated
@@ -122,6 +124,7 @@ def __init__( | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
base_url = _MULTIPART_URL_TEMPLATE.format(bucket_path=self.bucket.path) |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it the way you have it with one minor nit. This looks much better than before.
Thanks @HemangChothani
@@ -650,19 +648,24 @@ def _get_transport(self, client): | |||
client = self._require_client(client) | |||
return client._http | |||
|
|||
def _get_download_url(self): | |||
def _get_download_url(self, client): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 more question. Thanks for fixing this @HemangChothani!
google/cloud/storage/client.py
Outdated
@@ -530,7 +530,7 @@ def download_blob_to_file(self, blob_or_uri, file_obj, start=None, end=None): | |||
try: | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this an accidental miss in implementation? Seems like it but want to confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
bucket = Bucket(client, name=netloc) |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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: