Skip to content

Commit 41bad81

Browse files
authored
Merge branch 'main' into fix/506-parameter-defaults
2 parents a8c7d25 + c0f23b4 commit 41bad81

10 files changed

Lines changed: 300 additions & 144 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: adk
16+
on:
17+
pull_request:
18+
paths:
19+
- 'packages/toolbox-adk/**'
20+
- '!packages/toolbox-adk/**/*.md'
21+
pull_request_target:
22+
types: [labeled]
23+
24+
# Declare default permissions as read only.
25+
permissions: read-all
26+
27+
jobs:
28+
lint:
29+
if: "${{ github.event.action != 'labeled' || github.event.label.name == 'tests: run' }}"
30+
name: lint
31+
runs-on: ubuntu-latest
32+
concurrency:
33+
group: ${{ github.workflow }}-${{ github.ref }}
34+
cancel-in-progress: true
35+
defaults:
36+
run:
37+
working-directory: ./packages/toolbox-adk
38+
permissions:
39+
contents: 'read'
40+
issues: 'write'
41+
pull-requests: 'write'
42+
steps:
43+
- name: Remove PR Label
44+
if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}"
45+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
46+
with:
47+
github-token: ${{ secrets.GITHUB_TOKEN }}
48+
script: |
49+
try {
50+
await github.rest.issues.removeLabel({
51+
name: 'tests: run',
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
issue_number: context.payload.pull_request.number
55+
});
56+
} catch (e) {
57+
console.log('Failed to remove label. Another job may have already removed it!');
58+
}
59+
- name: Checkout code
60+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
61+
with:
62+
ref: ${{ github.event.pull_request.head.sha }}
63+
repository: ${{ github.event.pull_request.head.repo.full_name }}
64+
token: ${{ secrets.GITHUB_TOKEN }}
65+
- name: Setup Python
66+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
67+
with:
68+
python-version: "3.13"
69+
70+
- name: Install library requirements
71+
run: pip install -r requirements.txt
72+
73+
- name: Install test requirements
74+
run: pip install .[test]
75+
76+
- name: Run linters
77+
run: |
78+
black --check .
79+
isort --check .
80+
81+
- name: Run type-check
82+
env:
83+
MYPYPATH: './src'
84+
run: mypy --install-types --non-interactive --cache-dir=.mypy_cache/ -p toolbox_adk

packages/toolbox-adk/src/toolbox_adk/client.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ def _configure_auth(self, creds: CredentialConfig) -> None:
7979

8080
elif creds.type == CredentialType.WORKLOAD_IDENTITY:
8181
if not creds.target_audience:
82-
raise ValueError(
83-
"target_audience is required for WORKLOAD_IDENTITY"
84-
)
82+
raise ValueError("target_audience is required for WORKLOAD_IDENTITY")
8583

8684
# Create an async capable token getter
8785
self._core_client_headers["Authorization"] = self._create_adc_token_getter(
@@ -112,13 +110,15 @@ def get_user_token() -> str:
112110
return ""
113111
return f"Bearer {token}"
114112

115-
header_name = getattr(creds, "header_name", "Authorization") or "Authorization"
113+
header_name = (
114+
getattr(creds, "header_name", "Authorization") or "Authorization"
115+
)
116116
self._core_client_headers[header_name] = get_user_token
117117

118118
elif creds.type == CredentialType.API_KEY:
119119
if not creds.api_key or not creds.header_name:
120120
raise ValueError("api_key and header_name are required for API_KEY")
121-
121+
122122
self._core_client_headers[creds.header_name] = creds.api_key
123123

124124
def _create_adc_token_getter(self, audience: str) -> Callable[[], str]:
@@ -157,7 +157,9 @@ def get_token() -> str:
157157
def credential_config(self) -> Optional[CredentialConfig]:
158158
return self._credentials
159159

160-
async def load_toolset(self, toolset_name: str, **kwargs: Any) -> Any:
160+
async def load_toolset(
161+
self, toolset_name: Optional[str] = None, **kwargs: Any
162+
) -> Any:
161163
return await self._client.load_toolset(toolset_name, **kwargs)
162164

163165
async def load_tool(self, tool_name: str, **kwargs: Any) -> Any:

packages/toolbox-adk/src/toolbox_adk/credentials.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
from enum import Enum
1717
from typing import Any, Dict, List, Optional
1818

19-
from google.auth import credentials as google_creds
2019
from google.adk.auth.auth_credential import AuthCredential, AuthCredentialTypes
2120
from google.adk.auth.auth_tool import AuthConfig, AuthScheme
21+
from google.auth import credentials as google_creds
2222

2323

2424
class CredentialType(Enum):
@@ -173,9 +173,9 @@ def from_adk_credentials(
173173
):
174174
# Extract client_id, client_secret, and scopes from the credential object.
175175
return CredentialStrategy.user_identity(
176-
client_id=auth_credential.oauth2.client_id,
177-
client_secret=auth_credential.oauth2.client_secret,
178-
scopes=auth_credential.oauth2.scopes,
176+
client_id=auth_credential.oauth2.client_id or "",
177+
client_secret=auth_credential.oauth2.client_secret or "",
178+
scopes=getattr(auth_credential.oauth2, "scopes", []),
179179
)
180180

181181
# Handle HTTP Bearer
@@ -192,28 +192,28 @@ def from_adk_credentials(
192192
return CredentialStrategy.manual_token(
193193
token=auth_credential.http.credentials.token, scheme="Bearer"
194194
)
195-
196-
raise ValueError(
197-
f"Unsupported HTTP authentication scheme: {scheme_type}"
198-
)
195+
196+
raise ValueError(f"Unsupported HTTP authentication scheme: {scheme_type}")
199197

200198
if (
201199
auth_credential.auth_type == AuthCredentialTypes.API_KEY
202200
and auth_credential.api_key
203201
):
204202
if not auth_scheme:
205-
raise ValueError("API Key credentials require the auth_scheme definition.")
206-
203+
raise ValueError(
204+
"API Key credentials require the auth_scheme definition."
205+
)
206+
207207
header_name = getattr(auth_scheme, "name", None)
208208
if not header_name:
209209
raise ValueError("API Key scheme must define the header name.")
210-
210+
211211
location = getattr(auth_scheme, "in_", "header") or "header"
212212
# Handle Enum (APIKeyIn.header) or string values
213213
location_str = str(location)
214214
if "." in location_str:
215215
location_str = location_str.split(".")[-1]
216-
216+
217217
if location_str.lower() != "header":
218218
raise ValueError(
219219
f"Unsupported API Key location: {location}. Only 'header' is supported."

0 commit comments

Comments
 (0)