Skip to content

Commit 62adc03

Browse files
committed
fix(identity): refactor imports to use absolute paths in ve_identity
- Fix Non-standard docstrings - Remove veadk prefix in logger
1 parent 8018835 commit 62adc03

File tree

10 files changed

+130
-86
lines changed

10 files changed

+130
-86
lines changed

veadk/integrations/ve_identity/__init__.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,28 @@
2222
- WorkloadTokenManager: Manages workload access tokens with caching
2323
- AuthRequestProcessor: Handles OAuth2 flows in agent conversations
2424
25-
Example usage:
26-
from veadk.integrations.ve_identity import VeIdentityFunctionTool
27-
28-
@VeIdentityFunctionTool(
29-
provider_name="github",
30-
scopes=["repo", "user"],
31-
auth_flow="USER_FEDERATION",
25+
Examples:
26+
from veadk.integrations.ve_identity import (
27+
VeIdentityFunctionTool,
28+
oauth2_auth,
3229
)
30+
3331
async def get_github_repos(access_token: str):
3432
# Tool implementation
3533
pass
34+
35+
tool = VeIdentityFunctionTool(
36+
func=get_github_repos,
37+
auth_config=oauth2_auth(
38+
provider_name="github",
39+
scopes=["repo", "user"],
40+
auth_flow="USER_FEDERATION",
41+
),
42+
into="access_token",
43+
)
3644
"""
3745

38-
from .auth_processor import (
46+
from veadk.integrations.ve_identity.auth_processor import (
3947
AuthRequestConfig,
4048
AuthRequestProcessor,
4149
_NoOpAuthProcessor,
@@ -46,7 +54,7 @@ async def get_github_repos(access_token: str):
4654
)
4755

4856
# New unified tools
49-
from .auth_config import (
57+
from veadk.integrations.ve_identity.auth_config import (
5058
api_key_auth,
5159
oauth2_auth,
5260
workload_auth,
@@ -55,16 +63,19 @@ async def get_github_repos(access_token: str):
5563
WorkloadAuthConfig,
5664
VeIdentityAuthConfig,
5765
)
58-
from .function_tool import VeIdentityFunctionTool
59-
from .mcp_tool import VeIdentityMcpTool
60-
from .mcp_toolset import VeIdentityMcpToolset
61-
from .identity_client import IdentityClient
62-
from .models import (
66+
from veadk.integrations.ve_identity.function_tool import VeIdentityFunctionTool
67+
from veadk.integrations.ve_identity.mcp_tool import VeIdentityMcpTool
68+
from veadk.integrations.ve_identity.mcp_toolset import VeIdentityMcpToolset
69+
from veadk.integrations.ve_identity.identity_client import IdentityClient
70+
from veadk.integrations.ve_identity.models import (
6371
OAuth2TokenResponse,
6472
OAuth2AuthPoller,
6573
WorkloadToken,
6674
)
67-
from .token_manager import WorkloadTokenManager, get_workload_token
75+
from veadk.integrations.ve_identity.token_manager import (
76+
WorkloadTokenManager,
77+
get_workload_token,
78+
)
6879

6980
__all__ = [
7081
# Client

veadk/integrations/ve_identity/auth_config.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
from pydantic import BaseModel, model_validator, field_validator
2525

26-
from .models import OAuth2AuthPoller
27-
from .identity_client import IdentityClient
26+
from veadk.integrations.ve_identity.models import OAuth2AuthPoller
27+
from veadk.integrations.ve_identity.identity_client import IdentityClient
2828

2929

3030
class AuthConfig(BaseModel, ABC):
@@ -121,6 +121,7 @@ def _validate_required_fields(self):
121121
def auth_type(self) -> str:
122122
return "oauth2"
123123

124+
124125
class WorkloadAuthConfig(AuthConfig):
125126
"""Workload Access Token authentication configuration."""
126127

@@ -129,7 +130,6 @@ def auth_type(self) -> str:
129130
return "workload"
130131

131132

132-
133133
# Type alias for all auth configs
134134
VeIdentityAuthConfig = Union[ApiKeyAuthConfig, OAuth2AuthConfig, WorkloadAuthConfig]
135135

@@ -145,6 +145,7 @@ def api_key_auth(
145145
provider_name=provider_name, identity_client=identity_client, region=region
146146
)
147147

148+
148149
def workload_auth(
149150
provider_name: str,
150151
identity_client: Optional[IdentityClient] = None,
@@ -155,6 +156,7 @@ def workload_auth(
155156
provider_name=provider_name, identity_client=identity_client, region=region
156157
)
157158

159+
158160
def oauth2_auth(
159161
provider_name: str,
160162
scopes: List[str],

veadk/integrations/ve_identity/auth_mixins.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@
3737
from google.adk.tools.openapi_tool.auth.auth_helpers import dict_to_auth_scheme
3838
from google.adk.agents.readonly_context import ReadonlyContext
3939

40-
from .models import OAuth2AuthPoller, OAuth2TokenResponse
41-
from .identity_client import IdentityClient
42-
from .auth_config import (
40+
from veadk.integrations.ve_identity.models import OAuth2AuthPoller, OAuth2TokenResponse
41+
from veadk.integrations.ve_identity.identity_client import IdentityClient
42+
from veadk.integrations.ve_identity.auth_config import (
4343
VeIdentityAuthConfig,
4444
ApiKeyAuthConfig,
4545
OAuth2AuthConfig,
4646
WorkloadAuthConfig,
4747
)
48-
from .token_manager import get_workload_token
48+
from veadk.integrations.ve_identity.token_manager import get_workload_token
4949

5050
from veadk.utils.logger import get_logger
5151

52-
logger = get_logger("veadk." + __name__)
52+
logger = get_logger(__name__)
5353

5454

5555
# OAuth2 scheme definition (shared across all OAuth2 tools)
@@ -509,7 +509,7 @@ async def _handle_oauth2_flow_for_readonly_context(
509509

510510
def _create_default_oauth2_poller(self, auth_uri: str, request_dict: dict):
511511
"""Create a default OAuth2 poller for ReadonlyContext scenarios."""
512-
from .auth_processor import _DefaultOauth2AuthPoller
512+
from veadk.integrations.ve_identity.auth_processor import _DefaultOauth2AuthPoller
513513

514514
async def async_token_fetcher():
515515
response = await self._identity_client.get_oauth2_token_or_auth_url(

veadk/integrations/ve_identity/auth_processor.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
from google.genai import types
2626
from google.adk.auth.auth_credential import OAuth2Auth
2727

28-
from .identity_client import IdentityClient
29-
from .models import AuthRequestConfig, OAuth2AuthPoller
30-
from .utils import (
28+
from veadk.integrations.ve_identity.identity_client import IdentityClient
29+
from veadk.integrations.ve_identity.models import AuthRequestConfig, OAuth2AuthPoller
30+
from veadk.integrations.ve_identity.utils import (
3131
get_function_call_auth_config,
3232
get_function_call_id,
3333
is_pending_auth_event,
@@ -43,7 +43,7 @@
4343
from veadk.runner import Runner
4444

4545

46-
logger = get_logger("veadk." + __name__)
46+
logger = get_logger(__name__)
4747

4848
# Default configuration for token polling
4949
DEFAULT_POLLING_INTERVAL_SECONDS = 5
@@ -102,7 +102,10 @@ class _DefaultOauth2AuthPoller(OAuth2AuthPoller):
102102
def __init__(
103103
self,
104104
auth_url: str,
105-
polling_func: Callable[[], Optional[OAuth2Auth]] | Callable[[], Awaitable[Optional[OAuth2Auth]]],
105+
polling_func: (
106+
Callable[[], Optional[OAuth2Auth]]
107+
| Callable[[], Awaitable[Optional[OAuth2Auth]]]
108+
),
106109
):
107110
"""Initialize the OAuth2 auth poller.
108111
@@ -134,6 +137,7 @@ async def poll_for_auth(self) -> OAuth2Auth:
134137

135138
# Check if polling_func is async or sync
136139
import inspect
140+
137141
if inspect.iscoroutinefunction(self.polling_func):
138142
oauth2auth = await self.polling_func()
139143
else:
@@ -226,7 +230,9 @@ async def process_auth_request(
226230
# Use custom poller or default poller
227231
# Create async token fetcher for default poller
228232
async def async_token_fetcher():
229-
response = await self._identity_client.get_oauth2_token_or_auth_url(**request_dict)
233+
response = await self._identity_client.get_oauth2_token_or_auth_url(
234+
**request_dict
235+
)
230236
return (
231237
OAuth2Auth(access_token=response.access_token)
232238
if response.access_token and response.access_token.strip()

veadk/integrations/ve_identity/function_tool.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@
2323
from google.adk.tools.function_tool import FunctionTool
2424
from google.adk.tools.tool_context import ToolContext
2525

26-
from .auth_config import (
26+
from veadk.integrations.ve_identity.auth_config import (
2727
VeIdentityAuthConfig,
2828
ApiKeyAuthConfig,
2929
OAuth2AuthConfig,
3030
WorkloadAuthConfig,
3131
)
32-
from .auth_mixins import VeIdentityAuthMixin, AuthRequiredException
32+
from veadk.integrations.ve_identity.auth_mixins import (
33+
VeIdentityAuthMixin,
34+
AuthRequiredException,
35+
)
3336

3437
from veadk.utils.logger import get_logger
3538

36-
logger = get_logger("veadk." + __name__)
39+
logger = get_logger(__name__)
3740

3841

3942
class VeIdentityFunctionTool(VeIdentityAuthMixin, FunctionTool):

veadk/integrations/ve_identity/identity_client.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import volcenginesdkid
2828
import volcenginesdkcore
2929

30-
from .models import (
30+
from veadk.integrations.ve_identity.models import (
3131
DCRRegistrationRequest,
3232
DCRRegistrationResponse,
3333
OAuth2TokenResponse,
@@ -36,7 +36,7 @@
3636

3737
from veadk.utils.logger import get_logger
3838

39-
logger = get_logger("veadk." + __name__)
39+
logger = get_logger(__name__)
4040

4141

4242
def refresh_credentials(func):
@@ -123,9 +123,7 @@ async def create_oauth2_credential_provider(
123123

124124
# Use the SDK's built-in async support
125125
return await self._api_client.create_oauth2_credential_provider(
126-
volcenginesdkid.CreateOauth2CredentialProviderRequest(
127-
**request_params
128-
),
126+
volcenginesdkid.CreateOauth2CredentialProviderRequest(**request_params),
129127
async_req=True,
130128
)
131129

@@ -145,9 +143,7 @@ async def create_api_key_credential_provider(
145143

146144
# Use the SDK's built-in async support
147145
return await self._api_client.create_api_key_credential_provider(
148-
volcenginesdkid.CreateApiKeyCredentialProviderRequest(
149-
**request_params
150-
),
146+
volcenginesdkid.CreateApiKeyCredentialProviderRequest(**request_params),
151147
async_req=True,
152148
)
153149

@@ -229,9 +225,7 @@ def convert_response(
229225
logger.info("Retrieving workload access token...")
230226
resp: volcenginesdkid.GetWorkloadAccessTokenForUserIdResponse = (
231227
await self._api_client.get_workload_access_token(
232-
volcenginesdkid.GetWorkloadAccessTokenRequest(
233-
name=workload_name
234-
),
228+
volcenginesdkid.GetWorkloadAccessTokenRequest(name=workload_name),
235229
async_req=True,
236230
)
237231
)

veadk/integrations/ve_identity/mcp_tool.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from mcp.types import Tool as McpBaseTool
3030
except ImportError as e:
3131
import sys
32+
3233
if sys.version_info < (3, 10):
3334
raise ImportError(
3435
"MCP Tool requires Python 3.10 or above. Please upgrade your Python"
@@ -40,13 +41,16 @@
4041
from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager
4142
from google.adk.tools.mcp_tool.mcp_session_manager import retry_on_closed_resource
4243

43-
from .auth_config import VeIdentityAuthConfig
44-
from .auth_mixins import VeIdentityAuthMixin, AuthRequiredException
45-
from .utils import generate_headers
44+
from veadk.integrations.ve_identity.auth_config import VeIdentityAuthConfig
45+
from veadk.integrations.ve_identity.auth_mixins import (
46+
VeIdentityAuthMixin,
47+
AuthRequiredException,
48+
)
49+
from veadk.integrations.ve_identity.utils import generate_headers
4650

4751
from veadk.utils.logger import get_logger
4852

49-
logger = get_logger("veadk." + __name__)
53+
logger = get_logger(__name__)
5054

5155

5256
class VeIdentityMcpTool(VeIdentityAuthMixin, BaseTool):
@@ -149,11 +153,11 @@ async def run_async(
149153
return e.message
150154

151155
async def _execute_with_credential(
152-
self,
153-
*,
154-
args: dict[str, Any],
155-
tool_context: ToolContext,
156-
credential: AuthCredential
156+
self,
157+
*,
158+
args: dict[str, Any],
159+
tool_context: ToolContext,
160+
credential: AuthCredential,
157161
) -> Any:
158162
"""Execute the MCP tool with the provided credential.
159163
@@ -190,4 +194,4 @@ async def _run_async_impl(
190194
session = await self._mcp_session_manager.create_session(headers=headers)
191195

192196
response = await session.call_tool(self._mcp_tool.name, arguments=args)
193-
return response
197+
return response

0 commit comments

Comments
 (0)