Skip to content

Commit be6662e

Browse files
committed
adding secrets to sdk
1 parent 8de165c commit be6662e

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

python-sdk/exospherehost/node/BaseNode.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Secrets(BaseModel):
4848
"""
4949
pass
5050

51-
async def _execute(self, inputs: Inputs) -> Outputs | List[Outputs]:
51+
async def _execute(self, inputs: Inputs, secrets: Secrets) -> Outputs | List[Outputs]:
5252
"""
5353
Internal method to execute the node with validated inputs.
5454
@@ -59,6 +59,7 @@ async def _execute(self, inputs: Inputs) -> Outputs | List[Outputs]:
5959
Outputs | List[Outputs]: The output(s) produced by the node.
6060
"""
6161
self.inputs = inputs
62+
self.secrets = secrets
6263
return await self.execute()
6364

6465
@abstractmethod

python-sdk/exospherehost/runtime.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
22
import os
33
from asyncio import Queue, sleep
4-
from typing import List
4+
from typing import List, Dict
55

66
from pydantic import BaseModel, ValidationError
77
from .node.BaseNode import BaseNode
@@ -117,6 +117,12 @@ def _get_register_endpoint(self):
117117
"""
118118
return f"{self._state_manager_uri}/{str(self._state_manager_version)}/namespace/{self._namespace}/nodes/"
119119

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+
120126
async def _register(self):
121127
"""
122128
Register node schemas and runtime metadata with the state manager.
@@ -226,6 +232,22 @@ async def _notify_errored(self, state_id: str, error: str):
226232
if response.status != 200:
227233
logger.error(f"Failed to notify errored state {state_id}: {res}")
228234

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+
229251
def _validate_nodes(self):
230252
"""
231253
Validate that all provided nodes are valid BaseNode subclasses.
@@ -282,7 +304,8 @@ async def _worker(self):
282304

283305
try:
284306
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))
286309

287310
if outputs is None:
288311
outputs = []

0 commit comments

Comments
 (0)