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)
| 240 | /// bootstrap path, which uses `plain_channel` to call `IssueSandboxToken` |
| 241 | /// once before the steady-state Bearer-authenticated channel is built. |
| 242 | async 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 | |
| 283 | async fn acquire_k8s_sandbox_token( |
| 284 | endpoint: &str, |
no test coverage detected