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

Function policy_revision_to_json

crates/openshell-cli/src/run.rs:7246–7297  ·  view source on GitHub ↗
(
    scope: &str,
    sandbox: Option<&str>,
    active_version: Option<u32>,
    rev: &openshell_core::proto::SandboxPolicyRevision,
    status: PolicyStatus,
    view: PolicyGetView,
)

Source from the content-addressed store, hash-verified

7244}
7245
7246fn policy_revision_to_json(
7247 scope: &str,
7248 sandbox: Option<&str>,
7249 active_version: Option<u32>,
7250 rev: &openshell_core::proto::SandboxPolicyRevision,
7251 status: PolicyStatus,
7252 view: PolicyGetView,
7253) -> Result<serde_json::Value> {
7254 let mut obj = serde_json::Map::new();
7255 obj.insert("scope".to_string(), serde_json::json!(scope));
7256 if let Some(sandbox) = sandbox {
7257 obj.insert("sandbox".to_string(), serde_json::json!(sandbox));
7258 }
7259 obj.insert("version".to_string(), serde_json::json!(rev.version));
7260 obj.insert("hash".to_string(), serde_json::json!(rev.policy_hash));
7261 obj.insert(
7262 "status".to_string(),
7263 serde_json::json!(policy_status_json_name(status)),
7264 );
7265 if let Some(active_version) = active_version {
7266 obj.insert(
7267 "active_version".to_string(),
7268 serde_json::json!(active_version),
7269 );
7270 }
7271 if rev.created_at_ms > 0 {
7272 obj.insert(
7273 "created_at_ms".to_string(),
7274 serde_json::json!(rev.created_at_ms),
7275 );
7276 }
7277 if rev.loaded_at_ms > 0 {
7278 obj.insert(
7279 "loaded_at_ms".to_string(),
7280 serde_json::json!(rev.loaded_at_ms),
7281 );
7282 }
7283 if !rev.load_error.is_empty() {
7284 obj.insert("load_error".to_string(), serde_json::json!(rev.load_error));
7285 }
7286 if view.includes_policy() {
7287 let policy = match rev.policy.as_ref() {
7288 Some(policy) => {
7289 let policy = policy_for_view(policy, view);
7290 openshell_policy::sandbox_policy_to_json_value(policy.as_ref())?
7291 }
7292 None => serde_json::Value::Null,
7293 };
7294 obj.insert("policy".to_string(), policy);
7295 }
7296 Ok(serde_json::Value::Object(obj))
7297}
7298
7299fn policy_for_view(policy: &SandboxPolicy, view: PolicyGetView) -> Cow<'_, SandboxPolicy> {
7300 if view != PolicyGetView::Base {

Callers 2

Calls 4

policy_for_viewFunction · 0.85
includes_policyMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected