forked from googleapis/google-cloud-python
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(bigtable): forward auth/identity config to accelerator daemon #3
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
Open
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
95 changes: 95 additions & 0 deletions
95
packages/google-cloud-bigtable/tests/unit/data/test_accelerator_credentials.py
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 |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """Unit tests for the accelerator credential-safety guardrail: which auth | ||
| configuration the client forwards to the daemon vs. falls back to native for. | ||
| These exercise pure helpers on the async client without spinning up a full | ||
| client or event loop.""" | ||
|
|
||
| from google.api_core.client_options import ClientOptions | ||
|
|
||
| from google.cloud.bigtable.data._async.client import BigtableDataClientAsync | ||
|
|
||
|
|
||
| def _bare_client(): | ||
| """A client instance that skips __init__ (no network / event loop).""" | ||
| return object.__new__(BigtableDataClientAsync) | ||
|
|
||
|
|
||
| class TestInitAcceleratorConfig: | ||
| def test_no_config_forwards_default_scopes(self): | ||
| c = _bare_client() | ||
| c._init_accelerator_config(explicit_credentials=False, client_options=None) | ||
| assert c._accelerator_blocked_reason is None | ||
| assert "--scopes" in c._accelerator_flags | ||
| assert c._accelerator_env == {} | ||
|
|
||
| def test_explicit_credentials_blocks(self): | ||
| c = _bare_client() | ||
| c._init_accelerator_config(explicit_credentials=True, client_options=None) | ||
| assert c._accelerator_blocked_reason is not None | ||
| assert "credentials" in c._accelerator_blocked_reason | ||
|
|
||
| def test_api_key_blocks(self): | ||
| c = _bare_client() | ||
| c._init_accelerator_config( | ||
| explicit_credentials=False, client_options=ClientOptions(api_key="AIzaKEY") | ||
| ) | ||
| assert "api_key" in c._accelerator_blocked_reason | ||
|
|
||
| def test_client_cert_source_blocks(self): | ||
| c = _bare_client() | ||
| c._init_accelerator_config( | ||
| explicit_credentials=False, | ||
| client_options=ClientOptions(client_cert_source=lambda: (b"", b"")), | ||
| ) | ||
| assert "client_cert_source" in c._accelerator_blocked_reason | ||
|
|
||
| def test_forwards_non_secret_knobs(self): | ||
| c = _bare_client() | ||
| opts = ClientOptions( | ||
| scopes=["https://www.googleapis.com/auth/custom"], | ||
| quota_project_id="quota-proj", | ||
| api_endpoint="https://custom.example.com:443", | ||
| universe_domain="my-universe.example.com", | ||
| ) | ||
| c._init_accelerator_config(explicit_credentials=False, client_options=opts) | ||
| flags = c._accelerator_flags | ||
| assert flags[flags.index("--scopes") + 1] == ( | ||
| "https://www.googleapis.com/auth/custom" | ||
| ) | ||
| assert flags[flags.index("--quota-project") + 1] == "quota-proj" | ||
| # api_endpoint is normalized to host:port (scheme stripped). | ||
| assert flags[flags.index("--data-endpoint") + 1] == "custom.example.com:443" | ||
| assert flags[flags.index("--universe-domain") + 1] == "my-universe.example.com" | ||
| assert c._accelerator_blocked_reason is None | ||
|
|
||
| def test_default_universe_not_forwarded(self): | ||
| c = _bare_client() | ||
| c._init_accelerator_config( | ||
| explicit_credentials=False, | ||
| client_options=ClientOptions(universe_domain="googleapis.com"), | ||
| ) | ||
| assert "--universe-domain" not in c._accelerator_flags | ||
|
|
||
| def test_credentials_file_forwarded_as_env_path(self): | ||
| c = _bare_client() | ||
| c._init_accelerator_config( | ||
| explicit_credentials=False, | ||
| client_options=ClientOptions(credentials_file="/path/to/key.json"), | ||
| ) | ||
| assert c._accelerator_env["GOOGLE_APPLICATION_CREDENTIALS"] == ( | ||
| "/path/to/key.json" | ||
| ) | ||
| # The path is not a "secret" that blocks acceleration. | ||
| assert c._accelerator_blocked_reason is None |
Oops, something went wrong.
Oops, something went wrong.
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.