|
1 | 1 | import asyncio |
2 | 2 | import os |
3 | 3 | from asyncio import Queue, sleep |
4 | | -from typing import List |
| 4 | +from typing import List, Dict |
5 | 5 |
|
6 | 6 | from pydantic import BaseModel, ValidationError |
7 | 7 | from .node.BaseNode import BaseNode |
@@ -117,6 +117,12 @@ def _get_register_endpoint(self): |
117 | 117 | """ |
118 | 118 | return f"{self._state_manager_uri}/{str(self._state_manager_version)}/namespace/{self._namespace}/nodes/" |
119 | 119 |
|
| 120 | + def _get_secrets_endpoint(self, state_id: str): |
| 121 | + """ |
| 122 | + Construct the endpoint URL for getting secrets. |
| 123 | + """ |
| 124 | + return f"{self._state_manager_uri}/{str(self._state_manager_version)}/state/{state_id}/secrets" |
| 125 | + |
120 | 126 | async def _register(self): |
121 | 127 | """ |
122 | 128 | Register node schemas and runtime metadata with the state manager. |
@@ -226,6 +232,22 @@ async def _notify_errored(self, state_id: str, error: str): |
226 | 232 | if response.status != 200: |
227 | 233 | logger.error(f"Failed to notify errored state {state_id}: {res}") |
228 | 234 |
|
| 235 | + async def _get_secrets(self, state_id: str) -> Dict[str, str]: |
| 236 | + """ |
| 237 | + Get secrets for a state. |
| 238 | + """ |
| 239 | + async with ClientSession() as session: |
| 240 | + endpoint = self._get_secrets_endpoint(state_id) |
| 241 | + headers = {"x-api-key": self._key} |
| 242 | + |
| 243 | + async with session.get(endpoint, headers=headers) as response: # type: ignore |
| 244 | + res = await response.json() |
| 245 | + |
| 246 | + if response.status != 200: |
| 247 | + logger.error(f"Failed to get secrets for state {state_id}: {res}") |
| 248 | + |
| 249 | + return res |
| 250 | + |
229 | 251 | def _validate_nodes(self): |
230 | 252 | """ |
231 | 253 | Validate that all provided nodes are valid BaseNode subclasses. |
@@ -282,7 +304,8 @@ async def _worker(self): |
282 | 304 |
|
283 | 305 | try: |
284 | 306 | node = self._node_mapping[state["node_name"]] |
285 | | - outputs = await node()._execute(node.Inputs(**state["inputs"])) |
| 307 | + secrets = await self._get_secrets(state["state_id"]) |
| 308 | + outputs = await node()._execute(node.Inputs(**state["inputs"]), node.Secrets(**secrets)) |
286 | 309 |
|
287 | 310 | if outputs is None: |
288 | 311 | outputs = [] |
|
0 commit comments