Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,14 @@ def _init_accelerator_config(
credentials_file
)

# Identify this client to the daemon so it can construct the full
# User-Agent prefix (e.g. "python-v3.0.0a0-go-accelerator-v3.x.x").
# The daemon appends its own "-go-accelerator-vX.Y.Z" suffix.
self._accelerator_flags += [
"--caller-user-agent",
f"python-v{google.cloud.bigtable.__version__}",
]

def _resolve_principal(self) -> str | None:
"""Resolve this client's identity to a principal, using only local
signals — never a token-introspection or other external network call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ def _init_accelerator_config(
self._accelerator_env["GOOGLE_APPLICATION_CREDENTIALS"] = (
credentials_file
)
self._accelerator_flags += [
"--caller-user-agent",
f"python-v{google.cloud.bigtable.__version__}",
]

def _resolve_principal(self) -> str | None:
"""Resolve this client's identity to a principal, using only local
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from google.api_core.client_options import ClientOptions
from google.auth import compute_engine

import google.cloud.bigtable
from google.cloud.bigtable.data._async.client import (
BigtableDataClientAsync,
_AcceleratorUnverified,
Expand Down Expand Up @@ -110,6 +111,20 @@ def test_credentials_file_forwarded_as_env_path(self):
# The path is not a "secret" that blocks acceleration.
assert c._accelerator_blocked_reason is None

def test_caller_user_agent_always_forwarded(self):
c = _bare_client()
c._init_accelerator_config(explicit_credentials=False, client_options=None)
flags = c._accelerator_flags
expected = f"python-v{google.cloud.bigtable.__version__}"
assert flags[flags.index("--caller-user-agent") + 1] == expected

def test_caller_user_agent_forwarded_even_when_blocked(self):
c = _bare_client()
c._init_accelerator_config(explicit_credentials=True, client_options=None)
flags = c._accelerator_flags
expected = f"python-v{google.cloud.bigtable.__version__}"
assert flags[flags.index("--caller-user-agent") + 1] == expected


class TestResolvePrincipal:
def test_service_account_email(self):
Expand Down
Loading