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

Function read_local_token

crates/openshell-supervisor-process/src/debug_rpc.rs:189–210  ·  view source on GitHub ↗

Read the token from the env/file/SA-bootstrap chain, but only the "already a gateway JWT" paths — show-token / show-principal don't want to actually exchange an SA token.

()

Source from the content-addressed store, hash-verified

187/// "already a gateway JWT" paths — show-token / show-principal don't
188/// want to actually exchange an SA token.
189fn read_local_token() -> Result<String> {
190 if let Ok(t) = std::env::var(openshell_core::sandbox_env::SANDBOX_TOKEN)
191 && !t.is_empty()
192 {
193 return Ok(t);
194 }
195 if let Ok(path) = std::env::var(openshell_core::sandbox_env::SANDBOX_TOKEN_FILE)
196 && !path.is_empty()
197 {
198 return Ok(std::fs::read_to_string(&path)
199 .into_diagnostic()
200 .wrap_err_with(|| format!("failed to read sandbox token from {path}"))?
201 .trim()
202 .to_string());
203 }
204 Err(miette::miette!(
205 "no in-process gateway JWT available — set OPENSHELL_SANDBOX_TOKEN or \
206 OPENSHELL_SANDBOX_TOKEN_FILE. The K8s SA-bootstrap path is intentionally \
207 excluded from `show-token` / `show-principal` to avoid issuing a fresh \
208 token just for inspection."
209 ))
210}
211
212fn parse_flag<'a>(args: &'a [String], name: &str) -> Option<&'a str> {
213 let mut iter = args.iter();

Callers 2

run_show_tokenFunction · 0.85
run_show_principalFunction · 0.85

Calls 1

is_emptyMethod · 0.45

Tested by

no test coverage detected