MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / acquire_sandbox_token

Function acquire_sandbox_token

crates/openshell-core/src/grpc_client.rs:242–281  ·  view source on GitHub ↗

Resolve the sandbox JWT used to authenticate every outbound RPC. `endpoint` is logged on errors but never used for transport here; the actual network call lives inside this function only on the K8s bootstrap path, which uses `plain_channel` to call `IssueSandboxToken` once before the steady-state Bearer-authenticated channel is built.

(endpoint: &str, plain_channel: &Channel)

Source from the content-addressed store, hash-verified

240/// bootstrap path, which uses `plain_channel` to call `IssueSandboxToken`
241/// once before the steady-state Bearer-authenticated channel is built.
242async fn acquire_sandbox_token(endpoint: &str, plain_channel: &Channel) -> Result<AcquiredToken> {
243 if let Ok(t) = std::env::var(sandbox_env::SANDBOX_TOKEN)
244 && !t.is_empty()
245 {
246 debug!(source = "env", "loaded sandbox token");
247 return Ok(AcquiredToken {
248 token: t,
249 refresh_mode: RefreshMode::GatewayJwt(TokenSource::Env),
250 });
251 }
252
253 if let Ok(path) = std::env::var(sandbox_env::SANDBOX_TOKEN_FILE)
254 && !path.is_empty()
255 {
256 let contents = std::fs::read_to_string(&path)
257 .into_diagnostic()
258 .wrap_err_with(|| format!("failed to read sandbox token from {path}"))?;
259 debug!(source = "file", path = %path, "loaded sandbox token");
260 return Ok(AcquiredToken {
261 token: contents.trim().to_string(),
262 refresh_mode: RefreshMode::GatewayJwt(TokenSource::File),
263 });
264 }
265
266 if let Ok(sa_path) = std::env::var(sandbox_env::K8S_SA_TOKEN_FILE)
267 && !sa_path.is_empty()
268 {
269 return Ok(AcquiredToken {
270 token: acquire_k8s_sandbox_token(endpoint, plain_channel, &sa_path).await?,
271 refresh_mode: RefreshMode::GatewayJwt(TokenSource::K8sServiceAccount),
272 });
273 }
274
275 Err(miette::miette!(
276 "no sandbox token source available — set one of {}, {}, or {}",
277 sandbox_env::SANDBOX_TOKEN,
278 sandbox_env::SANDBOX_TOKEN_FILE,
279 sandbox_env::K8S_SA_TOKEN_FILE,
280 ))
281}
282
283async fn acquire_k8s_sandbox_token(
284 endpoint: &str,

Callers 1

token_slotFunction · 0.85

Calls 2

is_emptyMethod · 0.45

Tested by

no test coverage detected