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

Function sandbox_policy_get_global

crates/openshell-cli/src/run.rs:7176–7234  ·  view source on GitHub ↗
(
    server: &str,
    version: u32,
    view: PolicyGetView,
    output: &str,
    tls: &TlsOptions,
)

Source from the content-addressed store, hash-verified

7174}
7175
7176pub async fn sandbox_policy_get_global(
7177 server: &str,
7178 version: u32,
7179 view: PolicyGetView,
7180 output: &str,
7181 tls: &TlsOptions,
7182) -> Result<()> {
7183 let mut client = grpc_client(server, tls).await?;
7184
7185 let status_resp = client
7186 .get_sandbox_policy_status(GetSandboxPolicyStatusRequest {
7187 name: String::new(),
7188 version,
7189 global: true,
7190 })
7191 .await
7192 .into_diagnostic()?;
7193
7194 let inner = status_resp.into_inner();
7195 if let Some(rev) = inner.revision {
7196 let status = PolicyStatus::try_from(rev.status).unwrap_or(PolicyStatus::Unspecified);
7197 match output {
7198 "json" => {
7199 let obj = policy_revision_to_json("global", None, None, &rev, status, view)?;
7200 println!("{}", serde_json::to_string_pretty(&obj).into_diagnostic()?);
7201 return Ok(());
7202 }
7203 "table" => {}
7204 _ => return Err(miette!("unsupported output format: {output}")),
7205 }
7206
7207 println!("Scope: global");
7208 println!("Version: {}", rev.version);
7209 println!("Hash: {}", rev.policy_hash);
7210 println!("Status: {status:?}");
7211 if rev.created_at_ms > 0 {
7212 println!("Created: {} ms", rev.created_at_ms);
7213 }
7214 if rev.loaded_at_ms > 0 {
7215 println!("Loaded: {} ms", rev.loaded_at_ms);
7216 }
7217
7218 if view.includes_policy() {
7219 if let Some(ref policy) = rev.policy {
7220 println!("---");
7221 let policy = policy_for_view(policy, view);
7222 let yaml_str = openshell_policy::serialize_sandbox_policy(policy.as_ref())
7223 .wrap_err("failed to serialize policy to YAML")?;
7224 print!("{yaml_str}");
7225 } else {
7226 eprintln!("Policy payload not available for this version");
7227 }
7228 }
7229 } else {
7230 eprintln!("No global policy history found");
7231 }
7232
7233 Ok(())

Callers 1

mainFunction · 0.85

Calls 6

grpc_clientFunction · 0.85
policy_revision_to_jsonFunction · 0.85
policy_for_viewFunction · 0.85
serialize_sandbox_policyFunction · 0.85
includes_policyMethod · 0.80

Tested by

no test coverage detected