Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 173
feat: allow no project in client methods using storage emulator#703
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -33,6 +33,7 @@ | ||
| from google.cloud.exceptions import NotFound | ||
| from google.cloud.storage._helpers import _get_environ_project | ||
| from google.cloud.storage._helpers import _get_storage_host | ||
| from google.cloud.storage._helpers import _BASE_STORAGE_URI | ||
| from google.cloud.storage._helpers import _DEFAULT_STORAGE_HOST | ||
| from google.cloud.storage._helpers import _bucket_bound_hostname_url | ||
| from google.cloud.storage._helpers import _add_etag_match_headers | ||
| @@ -146,7 +147,7 @@ def __init__( | ||
| # STORAGE_EMULATOR_HOST or a non-default api_endpoint is set. | ||
| if ( | ||
| kw_args["api_endpoint"] is not None | ||
| and kw_args["api_endpoint"].find("storage.googleapis.com") < 0 | ||
| and _BASE_STORAGE_URI not in kw_args["api_endpoint"] | ||
| ): | ||
| if credentials is None: | ||
| credentials = AnonymousCredentials() | ||
| @@ -932,12 +933,22 @@ def create_bucket( | ||
| """ | ||
| bucket = self._bucket_arg_to_bucket(bucket_or_name) | ||
| query_params = {} | ||
| if project is None: | ||
| project = self.project | ||
| if project is None: | ||
| raise ValueError("Client project not set: pass an explicit project.") | ||
| # Use no project if STORAGE_EMULATOR_HOST is set | ||
| if _BASE_STORAGE_URI not in _get_storage_host(): | ||
| if project is None: | ||
| project = _get_environ_project() | ||
| if project is None: | ||
| project = "<none>" | ||
| # Only include the project parameter if a project is set. | ||
| # If a project is not set, falls back to API validation (BadRequest). | ||
| if project is not None: | ||
| query_params = {"project": project} | ||
| if requester_pays is not None: | ||
| warnings.warn( | ||
| @@ -947,8 +958,6 @@ def create_bucket( | ||
| ) | ||
| bucket.requester_pays = requester_pays | ||
| query_params = {"project": project} | ||
| if predefined_acl is not None: | ||
| predefined_acl = BucketACL.validate_predefined(predefined_acl) | ||
| query_params["predefinedAcl"] = predefined_acl | ||
| @@ -1375,13 +1384,22 @@ def list_buckets( | ||
| :returns: Iterator of all :class:`~google.cloud.storage.bucket.Bucket` | ||
| belonging to this project. | ||
| """ | ||
| extra_params = {} | ||
| if project is None: | ||
| project = self.project | ||
| if project is None: | ||
| raise ValueError("Client project not set: pass an explicit project.") | ||
| # Use no project if STORAGE_EMULATOR_HOST is set | ||
| if _BASE_STORAGE_URI not in _get_storage_host(): | ||
| if project is None: | ||
| project = _get_environ_project() | ||
| if project is None: | ||
| project = "<none>" | ||
| extra_params = {"project": project} | ||
| # Only include the project parameter if a project is set. | ||
| # If a project is not set, falls back to API validation (BadRequest). | ||
| if project is not None: | ||
unforced marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| extra_params = {"project": project} | ||
| if prefix is not None: | ||
| extra_params["prefix"] = prefix | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.