Skip to content

Commit 63421da

Browse files
OhYeeCopilot
andcommitted
refactor(auth): update RAM data domains and endpoint logic
Update RAM data domains to support both agentrun-data and funagent-data-pre endpoints, and refine the endpoint resolution logic for RAM authentication. Improve code formatting and remove unnecessary config parameter from get_base_url method. 更新 RAM 数据域以支持 agentrun-data 和 funagent-data-pre 端点, 并优化 RAM 认证的端点解析逻辑。 改进代码格式并从 get_base_url 方法中移除不必要的 config 参数。 Change-Id: I94555e7dda35fc7b40b232a456d074caacd97024 Co-authored-by: Copilot <copilot@github.com> Signed-off-by: OhYee <oyohyee@oyohyee.com>
1 parent eda73b9 commit 63421da

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

agentrun/integration/crewai/tool_adapter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ def from_canonical(self, tools: List[CanonicalTool]) -> Any:
1919
from crewai.tools import tool
2020
except ImportError as e:
2121
raise ImportError(
22-
"LangChain is not installed. "
23-
"Install it with: pip install langchain-core"
22+
"CrewAI is not installed. Install it with: pip install crewai"
2423
) from e
2524

2625
return [tool(t) for t in self.function_tools(tools)]

agentrun/utils/__data_api_async_template.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,22 @@ def _use_ram_auth(self, config: Optional[Config] = None) -> bool:
7575
cfg = Config.with_configs(self.config, config)
7676
return bool(cfg.get_access_key_id() and cfg.get_access_key_secret())
7777

78+
_RAM_DATA_DOMAINS = ("agentrun-data", "funagent-data-pre")
79+
7880
def _get_ram_data_endpoint(self, config: Optional[Config] = None) -> str:
79-
"""返回 RAM 鉴权用的 data endpoint(仅当默认 agentrun-data 域名时在 host 前加 -ram)。"""
81+
"""返回 RAM 鉴权用的 data endpoint(仅当 agentrun-data / funagent-data-pre 域名时在 host 前加 -ram)。"""
8082
cfg = Config.with_configs(self.config, config)
8183
base = cfg.get_data_endpoint()
8284
parsed = urlparse(base)
83-
if not parsed.netloc or ".agentrun-data." not in parsed.netloc:
85+
if not parsed.netloc or not any(
86+
f".{domain}." in parsed.netloc for domain in self._RAM_DATA_DOMAINS
87+
):
8488
return base
8589
parts = parsed.netloc.split(".", 1)
8690
if len(parts) != 2:
8791
return base
8892
ram_netloc = parts[0] + "-ram." + parts[1]
93+
8994
return urlunparse((
9095
parsed.scheme,
9196
ram_netloc,

agentrun/utils/data_api.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,22 @@ def _use_ram_auth(self, config: Optional[Config] = None) -> bool:
8585
cfg = Config.with_configs(self.config, config)
8686
return bool(cfg.get_access_key_id() and cfg.get_access_key_secret())
8787

88+
_RAM_DATA_DOMAINS = ("agentrun-data", "funagent-data-pre")
89+
8890
def _get_ram_data_endpoint(self, config: Optional[Config] = None) -> str:
89-
"""返回 RAM 鉴权用的 data endpoint(仅当默认 agentrun-data 域名时在 host 前加 -ram)。"""
91+
"""返回 RAM 鉴权用的 data endpoint(仅当 agentrun-data / funagent-data-pre 域名时在 host 前加 -ram)。"""
9092
cfg = Config.with_configs(self.config, config)
9193
base = cfg.get_data_endpoint()
9294
parsed = urlparse(base)
93-
if not parsed.netloc or ".agentrun-data." not in parsed.netloc:
95+
if not parsed.netloc or not any(
96+
f".{domain}." in parsed.netloc for domain in self._RAM_DATA_DOMAINS
97+
):
9498
return base
9599
parts = parsed.netloc.split(".", 1)
96100
if len(parts) != 2:
97101
return base
98102
ram_netloc = parts[0] + "-ram." + parts[1]
103+
99104
return urlunparse((
100105
parsed.scheme,
101106
ram_netloc,
@@ -105,35 +110,27 @@ def _get_ram_data_endpoint(self, config: Optional[Config] = None) -> str:
105110
parsed.fragment,
106111
))
107112

108-
def get_base_url(self, config: Optional[Config] = None) -> str:
113+
def get_base_url(self) -> str:
109114
"""
110115
Get the base URL for API requests.
111116
当使用 RAM 鉴权时返回 RAM 端点(host 带 -ram)。
112117
113-
Args:
114-
config: 可选,用于计算 base URL 的配置;未传时使用 self.config。
115-
116118
Returns:
117119
The base URL string
118120
"""
119-
cfg = Config.with_configs(self.config, config)
120-
if self._use_ram_auth(cfg):
121-
return self._get_ram_data_endpoint(cfg)
122-
return cfg.get_data_endpoint()
121+
if self._use_ram_auth():
122+
return self._get_ram_data_endpoint()
123+
return self.config.get_data_endpoint()
123124

124125
def with_path(
125-
self,
126-
path: str,
127-
query: Optional[Dict[str, Any]] = None,
128-
config: Optional[Config] = None,
126+
self, path: str, query: Optional[Dict[str, Any]] = None
129127
) -> str:
130128
"""
131129
Construct full URL with the given path and query parameters.
132130
133131
Args:
134132
path: API path (may include query string)
135133
query: Query parameters to add/merge
136-
config: 可选,用于计算 base URL 的配置;未传时使用 self.config。
137134
138135
Returns:
139136
Complete URL string with query parameters
@@ -153,7 +150,7 @@ def with_path(
153150
base_url = "/".join([
154151
part.strip("/")
155152
for part in [
156-
self.get_base_url(config),
153+
self.get_base_url(),
157154
self.namespace,
158155
path,
159156
]
@@ -209,8 +206,7 @@ def auth(
209206
body: Optional[bytes] = None,
210207
) -> tuple[str, Dict[str, str], Optional[Dict[str, Any]]]:
211208
"""
212-
Authentication: 仅使用 RAM 签名鉴权(Agentrun-Authorization)。
213-
需在 config 中配置 AK/SK。
209+
Authentication: 仅使用 RAM 签名鉴权(Agentrun-Authorization)。需在 config 中配置 AK/SK。
214210
"""
215211
cfg = Config.with_configs(self.config, config)
216212

@@ -232,9 +228,8 @@ def auth(
232228
**(headers or {}),
233229
}
234230
logger.debug(
235-
"using RAM signature for data API request to %s, token %s",
231+
"using RAM signature for data API request to %s",
236232
url[:80] + "..." if len(url) > 80 else url,
237-
signed,
238233
)
239234
except ValueError as e:
240235
logger.warning("RAM signing skipped (missing AK/SK): %s", e)
@@ -267,7 +262,6 @@ def _prepare_request(
267262
if headers:
268263
req_headers.update(headers)
269264

270-
# Build body bytes for RAM signing when applicable
271265
body_bytes: Optional[bytes] = None
272266
if data is not None:
273267
if isinstance(data, dict):

0 commit comments

Comments
 (0)