Skip to content

Commit f4bc9ec

Browse files
wukathloic-combis
authored andcommitted
fix: fallback to project id if crendetials don't contain quota project
Co-authored-by: Kathy Wu <wukathy@google.com> PiperOrigin-RevId: 914934690
1 parent d05c713 commit f4bc9ec

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/google/adk/integrations/agent_registry/agent_registry.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ def _get_auth_headers(self) -> Dict[str, str]:
208208
"Authorization": f"Bearer {self._credentials.token}",
209209
"Content-Type": "application/json",
210210
}
211-
quota_project_id = getattr(self._credentials, "quota_project_id", None)
211+
quota_project_id = (
212+
getattr(self._credentials, "quota_project_id", None)
213+
or self.project_id
214+
)
212215
if quota_project_id:
213216
headers["x-goog-user-project"] = quota_project_id
214217
return headers

tests/unittests/integrations/agent_registry/test_agent_registry.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,15 @@ def test_get_auth_headers(self, registry):
607607
assert headers["Authorization"] == "Bearer fake-token"
608608
assert headers["x-goog-user-project"] == "quota-project"
609609

610+
def test_get_auth_headers_fallback_to_project_id(self, registry):
611+
registry._credentials.token = "fake-token"
612+
registry._credentials.refresh = MagicMock()
613+
registry._credentials.quota_project_id = None
614+
615+
headers = registry._get_auth_headers()
616+
assert headers["Authorization"] == "Bearer fake-token"
617+
assert headers["x-goog-user-project"] == "test-project"
618+
610619
@patch("httpx.Client")
611620
def test_make_request_raises_http_status_error(self, mock_httpx, registry):
612621
mock_response = MagicMock()

0 commit comments

Comments
 (0)