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.
()
| 187 | /// "already a gateway JWT" paths — show-token / show-principal don't |
| 188 | /// want to actually exchange an SA token. |
| 189 | fn 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 | |
| 212 | fn parse_flag<'a>(args: &'a [String], name: &str) -> Option<&'a str> { |
| 213 | let mut iter = args.iter(); |
no test coverage detected