Skip to content

Commit 43912c0

Browse files
OhYeeCopilot
andcommitted
refactor(auth): update DataAPI to support optional config parameter
Update DataAPI methods to accept optional config parameter for flexible authentication configuration. This change allows passing custom config for RAM authentication scenarios while maintaining backward compatibility. The get_base_url method now accepts an optional config parameter, and the with_path method also supports optional config injection. Internal calls have been updated to properly propagate the config. 更新 DataAPI 以支持可选的配置参数 更新 DataAPI 方法以接受可选的配置参数,用于灵活的身份验证配置。此更改允许为 RAM 身份验证场景传递自定义配置, 同时保持向后兼容性。 get_base_url 方法现在接受一个可选的配置参数,with_path 方法也支持可选的配置注入。 内部调用已更新为正确传播配置。 Change-Id: Idd69af8d0f65e91733c3e02f1606b883fe5a9a4e Co-authored-by: Copilot <copilot@github.com> Signed-off-by: OhYee <oyohyee@oyohyee.com>
1 parent 172dc1f commit 43912c0

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

agentrun/utils/__data_api_async_template.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,24 @@ def _get_ram_data_endpoint(self, config: Optional[Config] = None) -> str:
100100
parsed.fragment,
101101
))
102102

103-
def get_base_url(self) -> str:
103+
def get_base_url(self, config: Optional[Config] = None) -> str:
104104
"""
105105
Get the base URL for API requests.
106106
当使用 RAM 鉴权时返回 RAM 端点(host 带 -ram)。
107107
108108
Returns:
109109
The base URL string
110110
"""
111-
if self._use_ram_auth():
112-
return self._get_ram_data_endpoint()
113-
return self.config.get_data_endpoint()
111+
if self._use_ram_auth(config):
112+
return self._get_ram_data_endpoint(config)
113+
cfg = Config.with_configs(self.config, config)
114+
return cfg.get_data_endpoint()
114115

115116
def with_path(
116-
self, path: str, query: Optional[Dict[str, Any]] = None
117+
self,
118+
path: str,
119+
query: Optional[Dict[str, Any]] = None,
120+
config: Optional[Config] = None,
117121
) -> str:
118122
"""
119123
Construct full URL with the given path and query parameters.
@@ -140,7 +144,7 @@ def with_path(
140144
base_url = "/".join([
141145
part.strip("/")
142146
for part in [
143-
self.get_base_url(),
147+
self.get_base_url(config),
144148
self.namespace,
145149
path,
146150
]

agentrun/utils/data_api.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,24 @@ def _get_ram_data_endpoint(self, config: Optional[Config] = None) -> str:
110110
parsed.fragment,
111111
))
112112

113-
def get_base_url(self) -> str:
113+
def get_base_url(self, config: Optional[Config] = None) -> str:
114114
"""
115115
Get the base URL for API requests.
116116
当使用 RAM 鉴权时返回 RAM 端点(host 带 -ram)。
117117
118118
Returns:
119119
The base URL string
120120
"""
121-
if self._use_ram_auth():
122-
return self._get_ram_data_endpoint()
123-
return self.config.get_data_endpoint()
121+
if self._use_ram_auth(config):
122+
return self._get_ram_data_endpoint(config)
123+
cfg = Config.with_configs(self.config, config)
124+
return cfg.get_data_endpoint()
124125

125126
def with_path(
126-
self, path: str, query: Optional[Dict[str, Any]] = None
127+
self,
128+
path: str,
129+
query: Optional[Dict[str, Any]] = None,
130+
config: Optional[Config] = None,
127131
) -> str:
128132
"""
129133
Construct full URL with the given path and query parameters.
@@ -150,7 +154,7 @@ def with_path(
150154
base_url = "/".join([
151155
part.strip("/")
152156
for part in [
153-
self.get_base_url(),
157+
self.get_base_url(config),
154158
self.namespace,
155159
path,
156160
]

0 commit comments

Comments
 (0)