veadk-python 0.2.27__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- veadk/__init__.py +37 -0
- veadk/a2a/__init__.py +13 -0
- veadk/a2a/agent_card.py +45 -0
- veadk/a2a/remote_ve_agent.py +390 -0
- veadk/a2a/utils/__init__.py +13 -0
- veadk/a2a/utils/agent_to_a2a.py +170 -0
- veadk/a2a/ve_a2a_server.py +93 -0
- veadk/a2a/ve_agent_executor.py +78 -0
- veadk/a2a/ve_middlewares.py +313 -0
- veadk/a2a/ve_task_store.py +37 -0
- veadk/agent.py +402 -0
- veadk/agent_builder.py +93 -0
- veadk/agents/loop_agent.py +68 -0
- veadk/agents/parallel_agent.py +72 -0
- veadk/agents/sequential_agent.py +64 -0
- veadk/auth/__init__.py +13 -0
- veadk/auth/base_auth.py +22 -0
- veadk/auth/ve_credential_service.py +203 -0
- veadk/auth/veauth/__init__.py +13 -0
- veadk/auth/veauth/apmplus_veauth.py +58 -0
- veadk/auth/veauth/ark_veauth.py +75 -0
- veadk/auth/veauth/base_veauth.py +50 -0
- veadk/auth/veauth/cozeloop_veauth.py +13 -0
- veadk/auth/veauth/opensearch_veauth.py +75 -0
- veadk/auth/veauth/postgresql_veauth.py +75 -0
- veadk/auth/veauth/prompt_pilot_veauth.py +60 -0
- veadk/auth/veauth/speech_veauth.py +54 -0
- veadk/auth/veauth/utils.py +69 -0
- veadk/auth/veauth/vesearch_veauth.py +62 -0
- veadk/auth/veauth/viking_mem0_veauth.py +91 -0
- veadk/cli/__init__.py +13 -0
- veadk/cli/cli.py +58 -0
- veadk/cli/cli_clean.py +87 -0
- veadk/cli/cli_create.py +163 -0
- veadk/cli/cli_deploy.py +233 -0
- veadk/cli/cli_eval.py +215 -0
- veadk/cli/cli_init.py +214 -0
- veadk/cli/cli_kb.py +110 -0
- veadk/cli/cli_pipeline.py +285 -0
- veadk/cli/cli_prompt.py +86 -0
- veadk/cli/cli_update.py +106 -0
- veadk/cli/cli_uploadevalset.py +139 -0
- veadk/cli/cli_web.py +143 -0
- veadk/cloud/__init__.py +13 -0
- veadk/cloud/cloud_agent_engine.py +485 -0
- veadk/cloud/cloud_app.py +475 -0
- veadk/config.py +115 -0
- veadk/configs/__init__.py +13 -0
- veadk/configs/auth_configs.py +133 -0
- veadk/configs/database_configs.py +132 -0
- veadk/configs/model_configs.py +78 -0
- veadk/configs/tool_configs.py +54 -0
- veadk/configs/tracing_configs.py +110 -0
- veadk/consts.py +74 -0
- veadk/evaluation/__init__.py +17 -0
- veadk/evaluation/adk_evaluator/__init__.py +17 -0
- veadk/evaluation/adk_evaluator/adk_evaluator.py +302 -0
- veadk/evaluation/base_evaluator.py +642 -0
- veadk/evaluation/deepeval_evaluator/__init__.py +17 -0
- veadk/evaluation/deepeval_evaluator/deepeval_evaluator.py +339 -0
- veadk/evaluation/eval_set_file_loader.py +48 -0
- veadk/evaluation/eval_set_recorder.py +146 -0
- veadk/evaluation/types.py +65 -0
- veadk/evaluation/utils/prometheus.py +196 -0
- veadk/integrations/__init__.py +13 -0
- veadk/integrations/ve_apig/__init__.py +13 -0
- veadk/integrations/ve_apig/ve_apig.py +349 -0
- veadk/integrations/ve_apig/ve_apig_utils.py +332 -0
- veadk/integrations/ve_code_pipeline/__init__.py +13 -0
- veadk/integrations/ve_code_pipeline/ve_code_pipeline.py +431 -0
- veadk/integrations/ve_cozeloop/__init__.py +13 -0
- veadk/integrations/ve_cozeloop/ve_cozeloop.py +96 -0
- veadk/integrations/ve_cr/__init__.py +13 -0
- veadk/integrations/ve_cr/ve_cr.py +220 -0
- veadk/integrations/ve_faas/__init__.py +13 -0
- veadk/integrations/ve_faas/template/cookiecutter.json +15 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/__init__.py +13 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/clean.py +23 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/config.yaml.example +6 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/deploy.py +106 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/__init__.py +13 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/agent.py +25 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/app.py +202 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/requirements.txt +3 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/run.sh +49 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{ cookiecutter.app_name }}/__init__.py +14 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{ cookiecutter.app_name }}/agent.py +27 -0
- veadk/integrations/ve_faas/ve_faas.py +754 -0
- veadk/integrations/ve_faas/ve_faas_utils.py +408 -0
- veadk/integrations/ve_faas/web_template/cookiecutter.json +20 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/__init__.py +13 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/clean.py +23 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/config.yaml.example +2 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/deploy.py +44 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/Dockerfile +23 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/app.py +123 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/init_db.py +46 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/models.py +36 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/requirements.txt +4 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/run.sh +21 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/static/css/style.css +368 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/static/js/admin.js +0 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/dashboard.html +21 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/edit_post.html +24 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/login.html +21 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/posts.html +53 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/base.html +45 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/index.html +29 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/post.html +14 -0
- veadk/integrations/ve_identity/__init__.py +110 -0
- veadk/integrations/ve_identity/auth_config.py +261 -0
- veadk/integrations/ve_identity/auth_mixins.py +650 -0
- veadk/integrations/ve_identity/auth_processor.py +385 -0
- veadk/integrations/ve_identity/function_tool.py +158 -0
- veadk/integrations/ve_identity/identity_client.py +864 -0
- veadk/integrations/ve_identity/mcp_tool.py +181 -0
- veadk/integrations/ve_identity/mcp_toolset.py +431 -0
- veadk/integrations/ve_identity/models.py +228 -0
- veadk/integrations/ve_identity/token_manager.py +188 -0
- veadk/integrations/ve_identity/utils.py +151 -0
- veadk/integrations/ve_prompt_pilot/__init__.py +13 -0
- veadk/integrations/ve_prompt_pilot/ve_prompt_pilot.py +85 -0
- veadk/integrations/ve_tls/__init__.py +13 -0
- veadk/integrations/ve_tls/utils.py +116 -0
- veadk/integrations/ve_tls/ve_tls.py +212 -0
- veadk/integrations/ve_tos/ve_tos.py +710 -0
- veadk/integrations/ve_viking_db_memory/__init__.py +13 -0
- veadk/integrations/ve_viking_db_memory/ve_viking_db_memory.py +308 -0
- veadk/knowledgebase/__init__.py +17 -0
- veadk/knowledgebase/backends/__init__.py +13 -0
- veadk/knowledgebase/backends/base_backend.py +72 -0
- veadk/knowledgebase/backends/in_memory_backend.py +91 -0
- veadk/knowledgebase/backends/opensearch_backend.py +162 -0
- veadk/knowledgebase/backends/redis_backend.py +172 -0
- veadk/knowledgebase/backends/utils.py +92 -0
- veadk/knowledgebase/backends/vikingdb_knowledge_backend.py +608 -0
- veadk/knowledgebase/entry.py +25 -0
- veadk/knowledgebase/knowledgebase.py +307 -0
- veadk/memory/__init__.py +35 -0
- veadk/memory/long_term_memory.py +365 -0
- veadk/memory/long_term_memory_backends/__init__.py +13 -0
- veadk/memory/long_term_memory_backends/base_backend.py +35 -0
- veadk/memory/long_term_memory_backends/in_memory_backend.py +67 -0
- veadk/memory/long_term_memory_backends/mem0_backend.py +155 -0
- veadk/memory/long_term_memory_backends/opensearch_backend.py +124 -0
- veadk/memory/long_term_memory_backends/redis_backend.py +140 -0
- veadk/memory/long_term_memory_backends/vikingdb_memory_backend.py +189 -0
- veadk/memory/short_term_memory.py +252 -0
- veadk/memory/short_term_memory_backends/__init__.py +13 -0
- veadk/memory/short_term_memory_backends/base_backend.py +31 -0
- veadk/memory/short_term_memory_backends/mysql_backend.py +49 -0
- veadk/memory/short_term_memory_backends/postgresql_backend.py +49 -0
- veadk/memory/short_term_memory_backends/sqlite_backend.py +55 -0
- veadk/memory/short_term_memory_processor.py +100 -0
- veadk/processors/__init__.py +26 -0
- veadk/processors/base_run_processor.py +120 -0
- veadk/prompts/__init__.py +13 -0
- veadk/prompts/agent_default_prompt.py +30 -0
- veadk/prompts/prompt_evaluator.py +20 -0
- veadk/prompts/prompt_memory_processor.py +55 -0
- veadk/prompts/prompt_optimization.py +150 -0
- veadk/runner.py +732 -0
- veadk/tools/__init__.py +13 -0
- veadk/tools/builtin_tools/__init__.py +13 -0
- veadk/tools/builtin_tools/agent_authorization.py +94 -0
- veadk/tools/builtin_tools/generate_image.py +23 -0
- veadk/tools/builtin_tools/image_edit.py +300 -0
- veadk/tools/builtin_tools/image_generate.py +446 -0
- veadk/tools/builtin_tools/lark.py +67 -0
- veadk/tools/builtin_tools/las.py +24 -0
- veadk/tools/builtin_tools/link_reader.py +66 -0
- veadk/tools/builtin_tools/llm_shield.py +381 -0
- veadk/tools/builtin_tools/load_knowledgebase.py +97 -0
- veadk/tools/builtin_tools/mcp_router.py +29 -0
- veadk/tools/builtin_tools/run_code.py +113 -0
- veadk/tools/builtin_tools/tts.py +253 -0
- veadk/tools/builtin_tools/vesearch.py +49 -0
- veadk/tools/builtin_tools/video_generate.py +363 -0
- veadk/tools/builtin_tools/web_scraper.py +76 -0
- veadk/tools/builtin_tools/web_search.py +83 -0
- veadk/tools/demo_tools.py +58 -0
- veadk/tools/load_knowledgebase_tool.py +149 -0
- veadk/tools/sandbox/__init__.py +13 -0
- veadk/tools/sandbox/browser_sandbox.py +37 -0
- veadk/tools/sandbox/code_sandbox.py +40 -0
- veadk/tools/sandbox/computer_sandbox.py +34 -0
- veadk/tracing/__init__.py +13 -0
- veadk/tracing/base_tracer.py +58 -0
- veadk/tracing/telemetry/__init__.py +13 -0
- veadk/tracing/telemetry/attributes/attributes.py +29 -0
- veadk/tracing/telemetry/attributes/extractors/common_attributes_extractors.py +180 -0
- veadk/tracing/telemetry/attributes/extractors/llm_attributes_extractors.py +858 -0
- veadk/tracing/telemetry/attributes/extractors/tool_attributes_extractors.py +152 -0
- veadk/tracing/telemetry/attributes/extractors/types.py +164 -0
- veadk/tracing/telemetry/exporters/__init__.py +13 -0
- veadk/tracing/telemetry/exporters/apmplus_exporter.py +558 -0
- veadk/tracing/telemetry/exporters/base_exporter.py +39 -0
- veadk/tracing/telemetry/exporters/cozeloop_exporter.py +129 -0
- veadk/tracing/telemetry/exporters/inmemory_exporter.py +248 -0
- veadk/tracing/telemetry/exporters/tls_exporter.py +139 -0
- veadk/tracing/telemetry/opentelemetry_tracer.py +320 -0
- veadk/tracing/telemetry/telemetry.py +411 -0
- veadk/types.py +47 -0
- veadk/utils/__init__.py +13 -0
- veadk/utils/audio_manager.py +95 -0
- veadk/utils/auth.py +294 -0
- veadk/utils/logger.py +59 -0
- veadk/utils/mcp_utils.py +44 -0
- veadk/utils/misc.py +184 -0
- veadk/utils/patches.py +101 -0
- veadk/utils/volcengine_sign.py +205 -0
- veadk/version.py +15 -0
- veadk_python-0.2.27.dist-info/METADATA +373 -0
- veadk_python-0.2.27.dist-info/RECORD +218 -0
- veadk_python-0.2.27.dist-info/WHEEL +5 -0
- veadk_python-0.2.27.dist-info/entry_points.txt +2 -0
- veadk_python-0.2.27.dist-info/licenses/LICENSE +201 -0
- veadk_python-0.2.27.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
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
|
+
"""Identity integration for ADK.
|
|
16
|
+
|
|
17
|
+
This module provides integration with VolcEngine Identity Service for managing
|
|
18
|
+
authentication and credentials in ADK agents.
|
|
19
|
+
|
|
20
|
+
Main components:
|
|
21
|
+
- IdentityClient: Low-level client for identity service API calls
|
|
22
|
+
- WorkloadTokenManager: Manages workload access tokens with caching
|
|
23
|
+
- AuthRequestProcessor: Handles OAuth2 flows in agent conversations
|
|
24
|
+
|
|
25
|
+
Examples:
|
|
26
|
+
from veadk.integrations.ve_identity import (
|
|
27
|
+
VeIdentityFunctionTool,
|
|
28
|
+
oauth2_auth,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
async def get_github_repos(access_token: str):
|
|
32
|
+
# Tool implementation
|
|
33
|
+
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
|
+
)
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
from veadk.integrations.ve_identity.auth_processor import (
|
|
47
|
+
AuthRequestConfig,
|
|
48
|
+
AuthRequestProcessor,
|
|
49
|
+
MockOauth2AuthPoller,
|
|
50
|
+
get_function_call_auth_config,
|
|
51
|
+
get_function_call_id,
|
|
52
|
+
is_pending_auth_event,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# New unified tools
|
|
56
|
+
from veadk.integrations.ve_identity.auth_config import (
|
|
57
|
+
api_key_auth,
|
|
58
|
+
oauth2_auth,
|
|
59
|
+
workload_auth,
|
|
60
|
+
ApiKeyAuthConfig,
|
|
61
|
+
OAuth2AuthConfig,
|
|
62
|
+
WorkloadAuthConfig,
|
|
63
|
+
VeIdentityAuthConfig,
|
|
64
|
+
get_default_identity_client,
|
|
65
|
+
)
|
|
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 (
|
|
71
|
+
OAuth2TokenResponse,
|
|
72
|
+
OAuth2AuthPoller,
|
|
73
|
+
WorkloadToken,
|
|
74
|
+
)
|
|
75
|
+
from veadk.integrations.ve_identity.token_manager import (
|
|
76
|
+
WorkloadTokenManager,
|
|
77
|
+
get_workload_token,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
__all__ = [
|
|
81
|
+
# Client
|
|
82
|
+
"IdentityClient",
|
|
83
|
+
# Token management
|
|
84
|
+
"WorkloadTokenManager",
|
|
85
|
+
"get_workload_token",
|
|
86
|
+
"VeIdentityFunctionTool",
|
|
87
|
+
"VeIdentityMcpTool",
|
|
88
|
+
"VeIdentityMcpToolset",
|
|
89
|
+
# Auth configurations
|
|
90
|
+
"api_key_auth",
|
|
91
|
+
"oauth2_auth",
|
|
92
|
+
"workload_auth",
|
|
93
|
+
"ApiKeyAuthConfig",
|
|
94
|
+
"OAuth2AuthConfig",
|
|
95
|
+
"WorkloadAuthConfig",
|
|
96
|
+
"VeIdentityAuthConfig",
|
|
97
|
+
# Auth processor
|
|
98
|
+
"AuthRequestProcessor",
|
|
99
|
+
"AuthRequestConfig",
|
|
100
|
+
"is_pending_auth_event",
|
|
101
|
+
"get_function_call_id",
|
|
102
|
+
"get_function_call_auth_config",
|
|
103
|
+
# Models
|
|
104
|
+
"OAuth2TokenResponse",
|
|
105
|
+
"WorkloadToken",
|
|
106
|
+
"OAuth2AuthPoller",
|
|
107
|
+
"MockOauth2AuthPoller",
|
|
108
|
+
# Utils
|
|
109
|
+
"get_default_identity_client",
|
|
110
|
+
]
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
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
|
+
"""
|
|
16
|
+
Authentication configuration classes for Identity integration.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from abc import ABC, abstractmethod
|
|
22
|
+
from typing import Any, Callable, List, Literal, Optional, Union
|
|
23
|
+
|
|
24
|
+
from pydantic import BaseModel, field_validator
|
|
25
|
+
|
|
26
|
+
from veadk.integrations.ve_identity.models import OAuth2AuthPoller
|
|
27
|
+
from veadk.integrations.ve_identity.identity_client import IdentityClient
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _get_default_region() -> str:
|
|
31
|
+
"""Get the default region from VeADK configuration.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
The configured region from VeIdentityConfig, or "cn-beijing" as fallback.
|
|
35
|
+
"""
|
|
36
|
+
try:
|
|
37
|
+
from veadk.config import settings
|
|
38
|
+
|
|
39
|
+
return settings.veidentity.region
|
|
40
|
+
except Exception:
|
|
41
|
+
# Fallback to default if config loading fails
|
|
42
|
+
return "cn-beijing"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def get_default_identity_client(region: Optional[str] = None) -> IdentityClient:
|
|
46
|
+
"""Get the default IdentityClient from VeADK configuration.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
The configured IdentityClient from VeIdentityConfig, or a new instance as fallback.
|
|
50
|
+
"""
|
|
51
|
+
try:
|
|
52
|
+
from veadk.config import settings
|
|
53
|
+
|
|
54
|
+
return settings.veidentity.get_identity_client()
|
|
55
|
+
except Exception:
|
|
56
|
+
# Fallback to new instance if config loading fails
|
|
57
|
+
return IdentityClient(region=region or _get_default_region())
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class AuthConfig(BaseModel, ABC):
|
|
61
|
+
"""Base authentication configuration."""
|
|
62
|
+
|
|
63
|
+
model_config = {"arbitrary_types_allowed": True}
|
|
64
|
+
|
|
65
|
+
provider_name: str
|
|
66
|
+
identity_client: Optional[IdentityClient] = None
|
|
67
|
+
region: str = None # Will be set to default from config if not provided
|
|
68
|
+
|
|
69
|
+
def __init__(self, **data):
|
|
70
|
+
"""Initialize AuthConfig with default region from VeADK config if not provided."""
|
|
71
|
+
if "region" not in data or data["region"] is None:
|
|
72
|
+
data["region"] = _get_default_region()
|
|
73
|
+
super().__init__(**data)
|
|
74
|
+
|
|
75
|
+
@field_validator("provider_name")
|
|
76
|
+
@classmethod
|
|
77
|
+
def validate_provider_name_not_empty(cls, v: str) -> str:
|
|
78
|
+
"""Validate that provider_name is not empty."""
|
|
79
|
+
if not v or not v.strip():
|
|
80
|
+
raise ValueError("provider_name cannot be empty")
|
|
81
|
+
return v.strip()
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
@abstractmethod
|
|
85
|
+
def auth_type(self) -> str:
|
|
86
|
+
"""Return the authentication type identifier."""
|
|
87
|
+
pass
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class ApiKeyAuthConfig(AuthConfig):
|
|
91
|
+
"""API Key authentication configuration."""
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def auth_type(self) -> str:
|
|
95
|
+
return "api_key"
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class OAuth2AuthConfig(AuthConfig):
|
|
99
|
+
"""OAuth2 authentication configuration."""
|
|
100
|
+
|
|
101
|
+
# Optional fields - control plane will use defaults if not provided
|
|
102
|
+
scopes: Optional[List[str]] = None
|
|
103
|
+
auth_flow: Optional[Literal["M2M", "USER_FEDERATION"]] = None
|
|
104
|
+
# Additional optional fields
|
|
105
|
+
callback_url: Optional[str] = None
|
|
106
|
+
force_authentication: bool = False
|
|
107
|
+
response_for_auth_required: Optional[Union[dict, str]] = None
|
|
108
|
+
on_auth_url: Optional[Callable[[str], Any]] = None
|
|
109
|
+
oauth2_auth_poller: Optional[Callable[[Any], OAuth2AuthPoller]] = None
|
|
110
|
+
|
|
111
|
+
@field_validator("scopes")
|
|
112
|
+
@classmethod
|
|
113
|
+
def validate_scopes_not_empty(cls, v: Optional[List[str]]) -> Optional[List[str]]:
|
|
114
|
+
"""Validate that scopes list is not empty and contains valid scope strings.
|
|
115
|
+
|
|
116
|
+
If scopes is None, the control plane will use default scopes.
|
|
117
|
+
"""
|
|
118
|
+
if v is None:
|
|
119
|
+
return None
|
|
120
|
+
|
|
121
|
+
if not v:
|
|
122
|
+
raise ValueError(
|
|
123
|
+
"scopes cannot be an empty list; use None to use control plane defaults"
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
# Validate each scope is not empty
|
|
127
|
+
for scope in v:
|
|
128
|
+
if not scope or not scope.strip():
|
|
129
|
+
raise ValueError("scope values cannot be empty")
|
|
130
|
+
|
|
131
|
+
# Remove duplicates while preserving order
|
|
132
|
+
seen = set()
|
|
133
|
+
unique_scopes = []
|
|
134
|
+
for scope in v:
|
|
135
|
+
scope = scope.strip()
|
|
136
|
+
if scope not in seen:
|
|
137
|
+
seen.add(scope)
|
|
138
|
+
unique_scopes.append(scope)
|
|
139
|
+
|
|
140
|
+
return unique_scopes
|
|
141
|
+
|
|
142
|
+
@field_validator("callback_url")
|
|
143
|
+
@classmethod
|
|
144
|
+
def validate_callback_url(cls, v: Optional[str]) -> Optional[str]:
|
|
145
|
+
"""Validate callback URL format if provided."""
|
|
146
|
+
if v is not None:
|
|
147
|
+
v = v.strip()
|
|
148
|
+
if not v:
|
|
149
|
+
return None
|
|
150
|
+
# Basic URL validation
|
|
151
|
+
if not (v.startswith("http://") or v.startswith("https://")):
|
|
152
|
+
raise ValueError("callback_url must be a valid HTTP/HTTPS URL")
|
|
153
|
+
return v
|
|
154
|
+
|
|
155
|
+
@property
|
|
156
|
+
def auth_type(self) -> str:
|
|
157
|
+
return "oauth2"
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class WorkloadAuthConfig(AuthConfig):
|
|
161
|
+
"""Workload Access Token authentication configuration."""
|
|
162
|
+
|
|
163
|
+
@property
|
|
164
|
+
def auth_type(self) -> str:
|
|
165
|
+
return "workload"
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
# Type alias for all auth configs
|
|
169
|
+
VeIdentityAuthConfig = Union[ApiKeyAuthConfig, OAuth2AuthConfig, WorkloadAuthConfig]
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
# Convenience factory functions
|
|
173
|
+
def api_key_auth(
|
|
174
|
+
provider_name: str,
|
|
175
|
+
identity_client: Optional[IdentityClient] = None,
|
|
176
|
+
region: Optional[str] = None,
|
|
177
|
+
) -> ApiKeyAuthConfig:
|
|
178
|
+
"""Create an API key authentication configuration.
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
provider_name: Name of the credential provider.
|
|
182
|
+
identity_client: Optional IdentityClient instance.
|
|
183
|
+
region: VolcEngine region. If not provided, uses the region from VeADK config.
|
|
184
|
+
|
|
185
|
+
Returns:
|
|
186
|
+
ApiKeyAuthConfig instance.
|
|
187
|
+
"""
|
|
188
|
+
if region is None:
|
|
189
|
+
region = _get_default_region()
|
|
190
|
+
return ApiKeyAuthConfig(
|
|
191
|
+
provider_name=provider_name, identity_client=identity_client, region=region
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def workload_auth(
|
|
196
|
+
provider_name: str,
|
|
197
|
+
identity_client: Optional[IdentityClient] = None,
|
|
198
|
+
region: Optional[str] = None,
|
|
199
|
+
) -> WorkloadAuthConfig:
|
|
200
|
+
"""Create a workload authentication configuration.
|
|
201
|
+
|
|
202
|
+
Args:
|
|
203
|
+
provider_name: Name of the credential provider.
|
|
204
|
+
identity_client: Optional IdentityClient instance.
|
|
205
|
+
region: VolcEngine region. If not provided, uses the region from VeADK config.
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
WorkloadAuthConfig instance.
|
|
209
|
+
"""
|
|
210
|
+
if region is None:
|
|
211
|
+
region = _get_default_region()
|
|
212
|
+
return WorkloadAuthConfig(
|
|
213
|
+
provider_name=provider_name, identity_client=identity_client, region=region
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def oauth2_auth(
|
|
218
|
+
provider_name: str,
|
|
219
|
+
scopes: Optional[List[str]] = None,
|
|
220
|
+
auth_flow: Optional[Literal["M2M", "USER_FEDERATION"]] = None,
|
|
221
|
+
callback_url: Optional[str] = None,
|
|
222
|
+
force_authentication: bool = False,
|
|
223
|
+
response_for_auth_required: Optional[Union[dict, str]] = None,
|
|
224
|
+
on_auth_url: Optional[Callable[[str], Any]] = None,
|
|
225
|
+
oauth2_auth_poller: Optional[Callable[[Any], OAuth2AuthPoller]] = None,
|
|
226
|
+
identity_client: Optional[IdentityClient] = None,
|
|
227
|
+
region: Optional[str] = None,
|
|
228
|
+
) -> OAuth2AuthConfig:
|
|
229
|
+
"""Create an OAuth2 authentication configuration.
|
|
230
|
+
|
|
231
|
+
Args:
|
|
232
|
+
provider_name: Name of the credential provider.
|
|
233
|
+
scopes: Optional list of OAuth2 scopes. If not provided, the control plane
|
|
234
|
+
will use the default configured scopes for the provider.
|
|
235
|
+
auth_flow: Optional authentication flow type ("M2M" or "USER_FEDERATION").
|
|
236
|
+
If not provided, the control plane will use the default configured flow.
|
|
237
|
+
callback_url: Optional callback URL for OAuth2.
|
|
238
|
+
force_authentication: Whether to force authentication.
|
|
239
|
+
response_for_auth_required: Response to return when auth is required.
|
|
240
|
+
on_auth_url: Callback function for auth URL.
|
|
241
|
+
oauth2_auth_poller: Callback function for auth polling.
|
|
242
|
+
identity_client: Optional IdentityClient instance.
|
|
243
|
+
region: VolcEngine region. If not provided, uses the region from VeADK config.
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
OAuth2AuthConfig instance.
|
|
247
|
+
"""
|
|
248
|
+
if region is None:
|
|
249
|
+
region = _get_default_region()
|
|
250
|
+
return OAuth2AuthConfig(
|
|
251
|
+
provider_name=provider_name,
|
|
252
|
+
scopes=scopes,
|
|
253
|
+
auth_flow=auth_flow,
|
|
254
|
+
callback_url=callback_url,
|
|
255
|
+
force_authentication=force_authentication,
|
|
256
|
+
response_for_auth_required=response_for_auth_required,
|
|
257
|
+
on_auth_url=on_auth_url,
|
|
258
|
+
oauth2_auth_poller=oauth2_auth_poller,
|
|
259
|
+
identity_client=identity_client,
|
|
260
|
+
region=region,
|
|
261
|
+
)
|