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,64 @@
|
|
|
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
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from google.adk.agents import SequentialAgent as GoogleADKSequentialAgent
|
|
18
|
+
from google.adk.agents.base_agent import BaseAgent
|
|
19
|
+
from pydantic import ConfigDict, Field
|
|
20
|
+
from typing_extensions import Any
|
|
21
|
+
|
|
22
|
+
from veadk.prompts.agent_default_prompt import DEFAULT_DESCRIPTION, DEFAULT_INSTRUCTION
|
|
23
|
+
from veadk.tracing.base_tracer import BaseTracer
|
|
24
|
+
from veadk.utils.logger import get_logger
|
|
25
|
+
from veadk.utils.patches import patch_asyncio
|
|
26
|
+
|
|
27
|
+
patch_asyncio()
|
|
28
|
+
logger = get_logger(__name__)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class SequentialAgent(GoogleADKSequentialAgent):
|
|
32
|
+
"""Sequential Agent that executes sub-agents sequentially.
|
|
33
|
+
|
|
34
|
+
This agent is designed to execute multiple sub-agents in a predefined sequential order.
|
|
35
|
+
It ensures that each sub-agent is executed one after the other, making it suitable for
|
|
36
|
+
workflows where the output of one sub-agent is needed as input for the next. The agent
|
|
37
|
+
is well-suited for tasks that require a linear progression of steps or operations, ensuring
|
|
38
|
+
that the execution flow is maintained.
|
|
39
|
+
|
|
40
|
+
Attributes:
|
|
41
|
+
model_config (ConfigDict): Configuration dictionary for the model.
|
|
42
|
+
name (str): The name of the agent, default is "veSequentialAgent".
|
|
43
|
+
description (str): A description of the agent, useful in A2A scenarios.
|
|
44
|
+
instruction (str): Instructions or principles for function calling and agent execution.
|
|
45
|
+
sub_agents (list[BaseAgent]): A list of sub-agents managed by the sequential agent.
|
|
46
|
+
Each sub-agent is executed in the order they are listed.
|
|
47
|
+
tracers (list[BaseTracer]): A list of tracers used for monitoring the agent's performance
|
|
48
|
+
and behavior during sequential execution.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
|
|
52
|
+
|
|
53
|
+
name: str = "veSequentialAgent"
|
|
54
|
+
description: str = DEFAULT_DESCRIPTION
|
|
55
|
+
instruction: str = DEFAULT_INSTRUCTION
|
|
56
|
+
|
|
57
|
+
sub_agents: list[BaseAgent] = Field(default_factory=list, exclude=True)
|
|
58
|
+
|
|
59
|
+
tracers: list[BaseTracer] = []
|
|
60
|
+
|
|
61
|
+
def model_post_init(self, __context: Any) -> None:
|
|
62
|
+
super().model_post_init(None) # for sub_agents init
|
|
63
|
+
|
|
64
|
+
logger.info(f"{self.__class__.__name__} `{self.name}` init done.")
|
veadk/auth/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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.
|
veadk/auth/base_auth.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
class BaseAuth:
|
|
17
|
+
def __init__(self) -> None: ...
|
|
18
|
+
|
|
19
|
+
def _fetch_token(self) -> str | dict: ...
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def token(self) -> str | dict: ...
|
|
@@ -0,0 +1,203 @@
|
|
|
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
|
+
"""A2A Credential Service for VeADK.
|
|
16
|
+
|
|
17
|
+
This module provides a credential service that supports direct credential
|
|
18
|
+
management by app_name and user_id, extending the ADK BaseCredentialService.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import logging
|
|
22
|
+
from typing import Optional
|
|
23
|
+
|
|
24
|
+
from typing_extensions import override
|
|
25
|
+
|
|
26
|
+
from google.adk.agents.callback_context import CallbackContext
|
|
27
|
+
from google.adk.auth.auth_credential import AuthCredential
|
|
28
|
+
from google.adk.auth.auth_tool import AuthConfig
|
|
29
|
+
from google.adk.auth.credential_service.base_credential_service import (
|
|
30
|
+
BaseCredentialService,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
logger = logging.getLogger(__name__)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class VeCredentialService(BaseCredentialService):
|
|
37
|
+
"""In-memory credential service with direct app_name/user_id access.
|
|
38
|
+
|
|
39
|
+
This service extends BaseCredentialService to support both:
|
|
40
|
+
1. Standard ADK credential operations (load_credential, save_credential)
|
|
41
|
+
2. Direct credential access by app_name and user_id
|
|
42
|
+
|
|
43
|
+
The credential store is organized as:
|
|
44
|
+
{
|
|
45
|
+
app_name: {
|
|
46
|
+
user_id: {
|
|
47
|
+
credential_key: AuthCredential
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
Examples:
|
|
53
|
+
```python
|
|
54
|
+
# Create service
|
|
55
|
+
service = VeCredentialService()
|
|
56
|
+
|
|
57
|
+
# Direct set/get
|
|
58
|
+
await service.set_credential(
|
|
59
|
+
app_name="my_app",
|
|
60
|
+
user_id="user123",
|
|
61
|
+
credential_key="bearer_token",
|
|
62
|
+
credential=AuthCredential(...)
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
credential = await service.get_credential(
|
|
66
|
+
app_name="my_app",
|
|
67
|
+
user_id="user123",
|
|
68
|
+
credential_key="bearer_token"
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# Standard ADK operations
|
|
72
|
+
await service.save_credential(auth_config, callback_context)
|
|
73
|
+
credential = await service.load_credential(auth_config, callback_context)
|
|
74
|
+
```
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
def __init__(self):
|
|
78
|
+
"""Initialize the credential service with empty storage."""
|
|
79
|
+
super().__init__()
|
|
80
|
+
self._credentials: dict[str, dict[str, dict[str, AuthCredential]]] = {}
|
|
81
|
+
|
|
82
|
+
@override
|
|
83
|
+
async def load_credential(
|
|
84
|
+
self,
|
|
85
|
+
auth_config: AuthConfig,
|
|
86
|
+
callback_context: CallbackContext,
|
|
87
|
+
) -> Optional[AuthCredential]:
|
|
88
|
+
"""Load credential from the store using auth config and callback context.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
auth_config: Auth configuration containing credential_key
|
|
92
|
+
callback_context: Callback context containing app_name and user_id
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
The stored AuthCredential, or None if not found
|
|
96
|
+
"""
|
|
97
|
+
app_name = callback_context._invocation_context.app_name
|
|
98
|
+
user_id = callback_context._invocation_context.user_id
|
|
99
|
+
|
|
100
|
+
return await self.get_credential(
|
|
101
|
+
app_name=app_name,
|
|
102
|
+
user_id=user_id,
|
|
103
|
+
credential_key=auth_config.credential_key,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
@override
|
|
107
|
+
async def save_credential(
|
|
108
|
+
self,
|
|
109
|
+
auth_config: AuthConfig,
|
|
110
|
+
callback_context: CallbackContext,
|
|
111
|
+
) -> None:
|
|
112
|
+
"""Save credential to the store using auth config and callback context.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
auth_config: Auth configuration containing credential_key and exchanged_auth_credential
|
|
116
|
+
callback_context: Callback context containing app_name and user_id
|
|
117
|
+
"""
|
|
118
|
+
app_name = callback_context._invocation_context.app_name
|
|
119
|
+
user_id = callback_context._invocation_context.user_id
|
|
120
|
+
|
|
121
|
+
await self.set_credential(
|
|
122
|
+
app_name=app_name,
|
|
123
|
+
user_id=user_id,
|
|
124
|
+
credential_key=auth_config.credential_key,
|
|
125
|
+
credential=auth_config.exchanged_auth_credential,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
async def set_credential(
|
|
129
|
+
self,
|
|
130
|
+
app_name: str,
|
|
131
|
+
user_id: str,
|
|
132
|
+
credential_key: str,
|
|
133
|
+
credential: AuthCredential,
|
|
134
|
+
) -> None:
|
|
135
|
+
"""Directly set a credential by app_name, user_id, and credential_key (async).
|
|
136
|
+
|
|
137
|
+
This method allows setting credentials without requiring a CallbackContext,
|
|
138
|
+
useful for middleware and request interceptors.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
app_name: Application name
|
|
142
|
+
user_id: User identifier
|
|
143
|
+
credential_key: Key to identify the credential
|
|
144
|
+
credential: The AuthCredential to store
|
|
145
|
+
|
|
146
|
+
Examples:
|
|
147
|
+
```python
|
|
148
|
+
from google.adk.auth.auth_credential import AuthCredential, AuthCredentialTypes
|
|
149
|
+
|
|
150
|
+
service = VeCredentialService()
|
|
151
|
+
await service.set_credential(
|
|
152
|
+
app_name="my_app",
|
|
153
|
+
user_id="user123",
|
|
154
|
+
credential_key="bearer_token",
|
|
155
|
+
credential=AuthCredential(
|
|
156
|
+
auth_type=AuthCredentialTypes.BEARER_TOKEN,
|
|
157
|
+
bearer_token="eyJhbGc..."
|
|
158
|
+
)
|
|
159
|
+
)
|
|
160
|
+
```
|
|
161
|
+
"""
|
|
162
|
+
if app_name not in self._credentials:
|
|
163
|
+
self._credentials[app_name] = {}
|
|
164
|
+
if user_id not in self._credentials[app_name]:
|
|
165
|
+
self._credentials[app_name][user_id] = {}
|
|
166
|
+
|
|
167
|
+
self._credentials[app_name][user_id][credential_key] = credential
|
|
168
|
+
logger.debug(
|
|
169
|
+
f"Set credential for app={app_name}, user={user_id}, key={credential_key}"
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
async def get_credential(
|
|
173
|
+
self,
|
|
174
|
+
app_name: str,
|
|
175
|
+
user_id: str,
|
|
176
|
+
credential_key: str,
|
|
177
|
+
) -> Optional[AuthCredential]:
|
|
178
|
+
"""Directly get a credential by app_name, user_id, and credential_key (async).
|
|
179
|
+
|
|
180
|
+
This method allows retrieving credentials without requiring a CallbackContext,
|
|
181
|
+
useful for middleware and request interceptors.
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
app_name: Application name
|
|
185
|
+
user_id: User identifier
|
|
186
|
+
credential_key: Key to identify the credential
|
|
187
|
+
|
|
188
|
+
Returns:
|
|
189
|
+
The stored AuthCredential, or None if not found
|
|
190
|
+
|
|
191
|
+
Examples:
|
|
192
|
+
```python
|
|
193
|
+
service = VeCredentialService()
|
|
194
|
+
credential = await service.get_credential(
|
|
195
|
+
app_name="my_app",
|
|
196
|
+
user_id="user123",
|
|
197
|
+
credential_key="bearer_token"
|
|
198
|
+
)
|
|
199
|
+
if credential:
|
|
200
|
+
print(f"Found token: {credential.bearer_token}")
|
|
201
|
+
```
|
|
202
|
+
"""
|
|
203
|
+
return self._credentials.get(app_name, {}).get(user_id, {}).get(credential_key)
|
|
@@ -0,0 +1,13 @@
|
|
|
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.
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
import os
|
|
16
|
+
|
|
17
|
+
from veadk.auth.veauth.utils import get_credential_from_vefaas_iam
|
|
18
|
+
from veadk.utils.logger import get_logger
|
|
19
|
+
from veadk.utils.volcengine_sign import ve_request
|
|
20
|
+
|
|
21
|
+
logger = get_logger(__name__)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_apmplus_token(region: str = "cn-beijing") -> str:
|
|
25
|
+
logger.info("Fetching APMPlus token...")
|
|
26
|
+
|
|
27
|
+
access_key = os.getenv("VOLCENGINE_ACCESS_KEY")
|
|
28
|
+
secret_key = os.getenv("VOLCENGINE_SECRET_KEY")
|
|
29
|
+
session_token = ""
|
|
30
|
+
|
|
31
|
+
if not (access_key and secret_key):
|
|
32
|
+
# try to get from vefaas iam
|
|
33
|
+
cred = get_credential_from_vefaas_iam()
|
|
34
|
+
access_key = cred.access_key_id
|
|
35
|
+
secret_key = cred.secret_access_key
|
|
36
|
+
session_token = cred.session_token
|
|
37
|
+
|
|
38
|
+
res = ve_request(
|
|
39
|
+
request_body={},
|
|
40
|
+
header={
|
|
41
|
+
"X-Security-Token": session_token,
|
|
42
|
+
# APMPlus frontend required
|
|
43
|
+
"X-Apmplus-Region": region.replace("-", "_"),
|
|
44
|
+
},
|
|
45
|
+
action="GetAppKey",
|
|
46
|
+
ak=access_key,
|
|
47
|
+
sk=secret_key,
|
|
48
|
+
service="apmplus_server",
|
|
49
|
+
version="2024-07-30",
|
|
50
|
+
region=region,
|
|
51
|
+
host="open.volcengineapi.com",
|
|
52
|
+
)
|
|
53
|
+
try:
|
|
54
|
+
api_key = res["data"]["app_key"]
|
|
55
|
+
logger.info("Successfully fetching APMPlus API Key.")
|
|
56
|
+
return api_key
|
|
57
|
+
except KeyError:
|
|
58
|
+
raise ValueError(f"Failed to get APMPlus token: {res}")
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
import os
|
|
16
|
+
|
|
17
|
+
from veadk.auth.veauth.utils import get_credential_from_vefaas_iam
|
|
18
|
+
from veadk.utils.logger import get_logger
|
|
19
|
+
from veadk.utils.volcengine_sign import ve_request
|
|
20
|
+
|
|
21
|
+
logger = get_logger(__name__)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_ark_token(region: str = "cn-beijing") -> str:
|
|
25
|
+
logger.info("Fetching ARK token...")
|
|
26
|
+
|
|
27
|
+
access_key = os.getenv("VOLCENGINE_ACCESS_KEY")
|
|
28
|
+
secret_key = os.getenv("VOLCENGINE_SECRET_KEY")
|
|
29
|
+
session_token = ""
|
|
30
|
+
|
|
31
|
+
if not (access_key and secret_key):
|
|
32
|
+
# try to get from vefaas iam
|
|
33
|
+
cred = get_credential_from_vefaas_iam()
|
|
34
|
+
access_key = cred.access_key_id
|
|
35
|
+
secret_key = cred.secret_access_key
|
|
36
|
+
session_token = cred.session_token
|
|
37
|
+
|
|
38
|
+
res = ve_request(
|
|
39
|
+
request_body={"ProjectName": "default", "Filter": {"AllowAll": True}},
|
|
40
|
+
header={"X-Security-Token": session_token},
|
|
41
|
+
action="ListApiKeys",
|
|
42
|
+
ak=access_key,
|
|
43
|
+
sk=secret_key,
|
|
44
|
+
service="ark",
|
|
45
|
+
version="2024-01-01",
|
|
46
|
+
region=region,
|
|
47
|
+
host="open.volcengineapi.com",
|
|
48
|
+
)
|
|
49
|
+
try:
|
|
50
|
+
first_api_key_id = res["Result"]["Items"][0]["Id"]
|
|
51
|
+
logger.warning("By default, VeADK fetches the first API Key in the list.")
|
|
52
|
+
logger.info(
|
|
53
|
+
f"Try to fetch ARK API Key with id={first_api_key_id}, name={res['Result']['Items'][0]['Name']}"
|
|
54
|
+
)
|
|
55
|
+
except KeyError:
|
|
56
|
+
raise ValueError(f"Failed to get ARK api key list: {res}")
|
|
57
|
+
|
|
58
|
+
# get raw api key
|
|
59
|
+
res = ve_request(
|
|
60
|
+
request_body={"Id": first_api_key_id},
|
|
61
|
+
header={"X-Security-Token": session_token},
|
|
62
|
+
action="GetRawApiKey",
|
|
63
|
+
ak=access_key,
|
|
64
|
+
sk=secret_key,
|
|
65
|
+
service="ark",
|
|
66
|
+
version="2024-01-01",
|
|
67
|
+
region=region,
|
|
68
|
+
host="open.volcengineapi.com",
|
|
69
|
+
)
|
|
70
|
+
try:
|
|
71
|
+
api_key = res["Result"]["ApiKey"]
|
|
72
|
+
logger.info(f"Successfully fetched ARK API Key (starts with {api_key[:8]}).")
|
|
73
|
+
return api_key
|
|
74
|
+
except KeyError:
|
|
75
|
+
raise ValueError(f"Failed to get ARK api key: {res}")
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
import os
|
|
16
|
+
from abc import ABC, abstractmethod
|
|
17
|
+
|
|
18
|
+
from veadk.auth.base_auth import BaseAuth
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class BaseVeAuth(ABC, BaseAuth):
|
|
22
|
+
volcengine_access_key: str
|
|
23
|
+
"""Volcengine Access Key"""
|
|
24
|
+
|
|
25
|
+
volcengine_secret_key: str
|
|
26
|
+
"""Volcengine Secret Key"""
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
access_key: str | None = None,
|
|
31
|
+
secret_key: str | None = None,
|
|
32
|
+
) -> None:
|
|
33
|
+
super().__init__()
|
|
34
|
+
|
|
35
|
+
final_ak = access_key or os.getenv("VOLCENGINE_ACCESS_KEY")
|
|
36
|
+
final_sk = secret_key or os.getenv("VOLCENGINE_SECRET_KEY")
|
|
37
|
+
|
|
38
|
+
assert final_ak, "Volcengine access key cannot be empty."
|
|
39
|
+
assert final_sk, "Volcengine secret key cannot be empty."
|
|
40
|
+
|
|
41
|
+
self.access_key = final_ak
|
|
42
|
+
self.secret_key = final_sk
|
|
43
|
+
|
|
44
|
+
self._token: str = ""
|
|
45
|
+
|
|
46
|
+
@abstractmethod
|
|
47
|
+
def _fetch_token(self) -> None: ...
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def token(self) -> str: ...
|
|
@@ -0,0 +1,13 @@
|
|
|
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.
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
16
|
+
#
|
|
17
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
18
|
+
# you may not use this file except in compliance with the License.
|
|
19
|
+
# You may obtain a copy of the License at
|
|
20
|
+
#
|
|
21
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
22
|
+
#
|
|
23
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
24
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
25
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
26
|
+
# See the License for the specific language governing permissions and
|
|
27
|
+
# limitations under the License.
|
|
28
|
+
|
|
29
|
+
import os
|
|
30
|
+
|
|
31
|
+
from typing_extensions import override
|
|
32
|
+
|
|
33
|
+
from veadk.auth.veauth.base_veauth import BaseVeAuth
|
|
34
|
+
from veadk.utils.logger import get_logger
|
|
35
|
+
|
|
36
|
+
# from veadk.utils.volcengine_sign import ve_request
|
|
37
|
+
|
|
38
|
+
logger = get_logger(__name__)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class OpensearchVeAuth(BaseVeAuth):
|
|
42
|
+
def __init__(
|
|
43
|
+
self,
|
|
44
|
+
access_key: str = os.getenv("VOLCENGINE_ACCESS_KEY", ""),
|
|
45
|
+
secret_key: str = os.getenv("VOLCENGINE_SECRET_KEY", ""),
|
|
46
|
+
) -> None:
|
|
47
|
+
super().__init__(access_key, secret_key)
|
|
48
|
+
|
|
49
|
+
self._token: str = ""
|
|
50
|
+
|
|
51
|
+
@override
|
|
52
|
+
def _fetch_token(self) -> None:
|
|
53
|
+
logger.info("Fetching Opensearch STS token...")
|
|
54
|
+
|
|
55
|
+
# res = ve_request(
|
|
56
|
+
# request_body={},
|
|
57
|
+
# action="GetOrCreatePromptPilotAPIKeys",
|
|
58
|
+
# ak=self.access_key,
|
|
59
|
+
# sk=self.secret_key,
|
|
60
|
+
# service="ark",
|
|
61
|
+
# version="2024-01-01",
|
|
62
|
+
# region="cn-beijing",
|
|
63
|
+
# host="open.volcengineapi.com",
|
|
64
|
+
# )
|
|
65
|
+
# try:
|
|
66
|
+
# self._token = res["Result"]["APIKeys"][0]["APIKey"]
|
|
67
|
+
# except KeyError:
|
|
68
|
+
# raise ValueError(f"Failed to get Prompt Pilot token: {res}")
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def token(self) -> str:
|
|
72
|
+
if self._token:
|
|
73
|
+
return self._token
|
|
74
|
+
self._fetch_token()
|
|
75
|
+
return self._token
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
16
|
+
#
|
|
17
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
18
|
+
# you may not use this file except in compliance with the License.
|
|
19
|
+
# You may obtain a copy of the License at
|
|
20
|
+
#
|
|
21
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
22
|
+
#
|
|
23
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
24
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
25
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
26
|
+
# See the License for the specific language governing permissions and
|
|
27
|
+
# limitations under the License.
|
|
28
|
+
|
|
29
|
+
import os
|
|
30
|
+
|
|
31
|
+
from typing_extensions import override
|
|
32
|
+
|
|
33
|
+
from veadk.auth.veauth.base_veauth import BaseVeAuth
|
|
34
|
+
from veadk.utils.logger import get_logger
|
|
35
|
+
|
|
36
|
+
# from veadk.utils.volcengine_sign import ve_request
|
|
37
|
+
|
|
38
|
+
logger = get_logger(__name__)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class PostgreSqlVeAuth(BaseVeAuth):
|
|
42
|
+
def __init__(
|
|
43
|
+
self,
|
|
44
|
+
access_key: str = os.getenv("VOLCENGINE_ACCESS_KEY", ""),
|
|
45
|
+
secret_key: str = os.getenv("VOLCENGINE_SECRET_KEY", ""),
|
|
46
|
+
) -> None:
|
|
47
|
+
super().__init__(access_key, secret_key)
|
|
48
|
+
|
|
49
|
+
self._token: str = ""
|
|
50
|
+
|
|
51
|
+
@override
|
|
52
|
+
def _fetch_token(self) -> None:
|
|
53
|
+
logger.info("Fetching PostgreSQL STS token...")
|
|
54
|
+
|
|
55
|
+
# res = ve_request(
|
|
56
|
+
# request_body={},
|
|
57
|
+
# action="GetOrCreatePromptPilotAPIKeys",
|
|
58
|
+
# ak=self.access_key,
|
|
59
|
+
# sk=self.secret_key,
|
|
60
|
+
# service="ark",
|
|
61
|
+
# version="2024-01-01",
|
|
62
|
+
# region="cn-beijing",
|
|
63
|
+
# host="open.volcengineapi.com",
|
|
64
|
+
# )
|
|
65
|
+
# try:
|
|
66
|
+
# self._token = res["Result"]["APIKeys"][0]["APIKey"]
|
|
67
|
+
# except KeyError:
|
|
68
|
+
# raise ValueError(f"Failed to get Prompt Pilot token: {res}")
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def token(self) -> str:
|
|
72
|
+
if self._token:
|
|
73
|
+
return self._token
|
|
74
|
+
self._fetch_token()
|
|
75
|
+
return self._token
|