feat: use bigquery scope by default in bigquery credentials.

Right now the agent builder has to specify the bigquery scope explicitly for bigquery tools, which is somewhat unnecessary. With this change the user does not have to specify scopes, although they would still have the ability to overrides scopes if necessary.

PiperOrigin-RevId: 765354010
This commit is contained in:
Google Team Member
2025-05-30 15:12:20 -07:00
committed by Copybara-Service
parent 8759a25251
commit ba5b80d5d7
3 changed files with 56 additions and 11 deletions

View File

@@ -34,6 +34,7 @@ from ...auth import OAuth2Auth
from ..tool_context import ToolContext
BIGQUERY_TOKEN_CACHE_KEY = "bigquery_token_cache"
BIGQUERY_DEFAULT_SCOPE = ["https://www.googleapis.com/auth/bigquery"]
class BigQueryCredentialsConfig(BaseModel):
@@ -66,15 +67,14 @@ class BigQueryCredentialsConfig(BaseModel):
client_secret: Optional[str] = None
"""the oauth client secret to use."""
scopes: Optional[List[str]] = None
"""the scopes to use.
"""
"""the scopes to use."""
@model_validator(mode="after")
def __post_init__(self) -> BigQueryCredentialsConfig:
"""Validate that either credentials or client ID/secret are provided."""
if not self.credentials and (not self.client_id or not self.client_secret):
raise ValueError(
"Must provide either credentials or client_id abd client_secret pair."
"Must provide either credentials or client_id and client_secret pair."
)
if self.credentials and (
self.client_id or self.client_secret or self.scopes
@@ -88,6 +88,10 @@ class BigQueryCredentialsConfig(BaseModel):
self.client_id = self.credentials.client_id
self.client_secret = self.credentials.client_secret
self.scopes = self.credentials.scopes
if not self.scopes:
self.scopes = BIGQUERY_DEFAULT_SCOPE
return self