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: add support for use_auth_w_custom_endpoint#901
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
facbbd4
feat: add support for use_auth_w_custom_endpoint
cojenco be320c8
update docstring
cojenco db7b8b8
handle emulator cases
cojenco 11c3fbc
Merge branch 'main' into custom-endpoint
cojenco 64db271
set default storage host as constant
cojenco b5aed85
Merge branch 'main' into custom-endpoint
cojenco 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 |
|---|---|---|
| @@ -96,6 +96,12 @@ class Client(ClientWithProject): | ||
| :type client_options: :class:`~google.api_core.client_options.ClientOptions` or :class:`dict` | ||
| :param client_options: (Optional) Client options used to set user options on the client. | ||
| API Endpoint should be set through client_options. | ||
| :type use_auth_w_custom_endpoint: bool | ||
| :param use_auth_w_custom_endpoint: | ||
| (Optional) Whether authentication is required under custom endpoints. | ||
| If false, uses AnonymousCredentials and bypasses authentication. | ||
| Defaults to True. Note this is only used when a custom endpoint is set in conjunction. | ||
| """ | ||
| SCOPE = ( | ||
| @@ -112,6 +118,7 @@ def __init__( | ||
| _http=None, | ||
| client_info=None, | ||
| client_options=None, | ||
| use_auth_w_custom_endpoint=True, | ||
| ): | ||
| self._base_connection = None | ||
| @@ -132,7 +139,7 @@ def __init__( | ||
| # then mTLS logic will be applied to decide which endpoint will be used. | ||
| storage_host = _get_storage_host() | ||
| kw_args["api_endpoint"] = ( | ||
| storage_host if storage_host != _DEFAULT_STORAGE_HOST else None | ||
| storage_host if storage_host != _BASE_STORAGE_URI else None | ||
| ) | ||
| if client_options: | ||
| @@ -144,19 +151,23 @@ def __init__( | ||
| api_endpoint = client_options.api_endpoint | ||
| kw_args["api_endpoint"] = api_endpoint | ||
| # Use anonymous credentials and no project when | ||
| # STORAGE_EMULATOR_HOST or a non-default api_endpoint is set. | ||
| if ( | ||
| kw_args["api_endpoint"] is not None | ||
| and _BASE_STORAGE_URI not in kw_args["api_endpoint"] | ||
| ): | ||
| if credentials is None: | ||
| credentials = AnonymousCredentials() | ||
| if project is None: | ||
| project = _get_environ_project() | ||
| if project is None: | ||
| no_project = True | ||
| project = "<none>" | ||
| # If a custom endpoint is set, the client checks for credentials | ||
| # or finds the default credentials based on the current environment. | ||
| # Authentication may be bypassed under certain conditions: | ||
| # (1) STORAGE_EMULATOR_HOST is set (for backwards compatibility), OR | ||
| # (2) use_auth_w_custom_endpoint is set to False. | ||
| if kw_args["api_endpoint"] is not None: | ||
| if ( | ||
| kw_args["api_endpoint"] == storage_host | ||
| or not use_auth_w_custom_endpoint | ||
| ): | ||
| if credentials is None: | ||
| credentials = AnonymousCredentials() | ||
| if project is None: | ||
| project = _get_environ_project() | ||
| if project is None: | ||
| no_project = True | ||
| project = "<none>" | ||
| super(Client, self).__init__( | ||
| project=project, | ||
| @@ -897,7 +908,7 @@ def create_bucket( | ||
| project = self.project | ||
| # Use no project if STORAGE_EMULATOR_HOST is set | ||
| if _BASE_STORAGE_URI not in _get_storage_host(): | ||
| if _get_storage_host() != _DEFAULT_STORAGE_HOST: | ||
cojenco marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if project is None: | ||
| project = _get_environ_project() | ||
| if project is None: | ||
| @@ -1327,7 +1338,7 @@ def list_buckets( | ||
| project = self.project | ||
| # Use no project if STORAGE_EMULATOR_HOST is set | ||
| if _BASE_STORAGE_URI not in _get_storage_host(): | ||
| if _get_storage_host() != _DEFAULT_STORAGE_HOST: | ||
| if project is None: | ||
| project = _get_environ_project() | ||
| if project is None: | ||
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.