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

Function sandbox_get

crates/openshell-cli/src/run.rs:2610–2719  ·  view source on GitHub ↗

Fetch a sandbox by name. Policy always comes from [`GetSandboxConfig`] (effective active policy, sandbox or global). With `policy_only`, prints only that YAML to stdout; otherwise prints sandbox metadata and the same policy with formatted YAML.

(
    server: &str,
    name: &str,
    policy_only: bool,
    tls: &TlsOptions,
)

Source from the content-addressed store, hash-verified

2608/// or global). With `policy_only`, prints only that YAML to stdout; otherwise
2609/// prints sandbox metadata and the same policy with formatted YAML.
2610pub async fn sandbox_get(
2611 server: &str,
2612 name: &str,
2613 policy_only: bool,
2614 tls: &TlsOptions,
2615) -> Result<()> {
2616 let mut client = grpc_client(server, tls).await?;
2617
2618 let response = client
2619 .get_sandbox(GetSandboxRequest {
2620 name: name.to_string(),
2621 })
2622 .await
2623 .into_diagnostic()?;
2624 let sandbox = response
2625 .into_inner()
2626 .sandbox
2627 .ok_or_else(|| miette::miette!("sandbox missing from response"))?;
2628
2629 let sandbox_id = if sandbox.object_id().is_empty() {
2630 return Err(miette::miette!("sandbox missing metadata"));
2631 } else {
2632 sandbox.object_id().to_string()
2633 };
2634
2635 let config = client
2636 .get_sandbox_config(GetSandboxConfigRequest { sandbox_id })
2637 .await
2638 .into_diagnostic()?
2639 .into_inner();
2640
2641 if policy_only {
2642 let Some(ref policy) = config.policy else {
2643 return Err(miette::miette!(
2644 "no active policy configured for this sandbox"
2645 ));
2646 };
2647 let yaml_str = openshell_policy::serialize_sandbox_policy(policy)
2648 .wrap_err("failed to serialize policy to YAML")?;
2649 print!("{yaml_str}");
2650 return Ok(());
2651 }
2652
2653 println!("{}", "Sandbox:".cyan().bold());
2654 println!();
2655 let id = if sandbox.object_id().is_empty() {
2656 "unknown"
2657 } else {
2658 sandbox.object_id()
2659 };
2660 let name = if sandbox.object_name().is_empty() {
2661 "unknown"
2662 } else {
2663 sandbox.object_name()
2664 };
2665 println!(" {} {}", "Id:".dimmed(), id);
2666 println!(" {} {}", "Name:".dimmed(), name);
2667 println!(" {} {}", "Phase:".dimmed(), phase_name(sandbox.phase()));

Calls 8

grpc_clientFunction · 0.85
serialize_sandbox_policyFunction · 0.85
print_sandbox_policyFunction · 0.85
object_idMethod · 0.80
object_nameMethod · 0.80
get_sandboxMethod · 0.45
is_emptyMethod · 0.45
get_sandbox_configMethod · 0.45