use serde_json::Value;
use vta_sdk::prelude::*;
pub async fn cmd_policy_show(client: &VtaClient) -> Result<(), Box<dyn std::error::Error>> {
let policy = client.get_step_up_policy().await?;
print_policy(&policy);
Ok(())
}
pub async fn cmd_policy_set(
client: &VtaClient,
policy: Value,
) -> Result<(), Box<dyn std::error::Error>> {
let effective = client.set_step_up_policy(policy).await?;
println!("Step-up policy updated:");
print_policy(&effective);
Ok(())
}
pub async fn cmd_policy_disable(client: &VtaClient) -> Result<(), Box<dyn std::error::Error>> {
let effective = client
.set_step_up_policy(serde_json::json!({ "enabled": false, "floors": [] }))
.await?;
println!("Step-up policy disabled (AAL1 everywhere):");
print_policy(&effective);
Ok(())
}
pub fn print_policy(p: &Value) {
let enabled = p.get("enabled").and_then(Value::as_bool).unwrap_or(false);
println!(
" Enforcement: {}",
if enabled {
"ENABLED"
} else {
"disabled (AAL1 everywhere)"
}
);
let floors = p.get("floors").and_then(Value::as_array);
match floors {
Some(floors) if !floors.is_empty() => {
println!(" Floors:");
for f in floors {
let op = f.get("operation").and_then(Value::as_str).unwrap_or("?");
let mode = f.get("mode").and_then(Value::as_str).unwrap_or("?");
let carve = f
.get("allowAal1IfNonEscalating")
.and_then(Value::as_bool)
.unwrap_or(false);
let suffix = if carve {
" (AAL1 carve-out for non-escalating self-service)"
} else {
""
};
println!(" {op:<18} → {mode}{suffix}");
}
}
_ => println!(" Floors: (none)"),
}
}