Skip to main content

krust/commands/
status.rs

1use anyhow::{Context, Result};
2
3use super::hab;
4
5pub async fn handle_status(name: &str, alias: &str) -> Result<()> {
6    let mut hby = hab::open(name, None)?;
7    let hab = hby.hab_by_name(alias)
8        .with_context(|| format!("Identifier '{}' not found", alias))?;
9    let state = hab.kever()?.state()
10        .map_err(|e| anyhow::anyhow!("Failed to load key state for '{}': {}", alias, e))?;
11    drop(hab);
12
13    let sn = u64::from_str_radix(&state.s, 16).unwrap_or(0);
14
15    println!("Identifier: {}", alias);
16    println!("  Prefix:     {}", state.i);
17    println!("  Seq No:     {}", sn);
18    println!("  Event Type: {}", event_type_label(&state.et));
19    println!("  Digest:     {}", state.d);
20
21    println!("  Keys:");
22    println!("    Signing Threshold: {}", state.kt);
23    for (i, k) in state.k.iter().enumerate() {
24        println!("    [{}] {}", i, k);
25    }
26
27    println!("  Next Keys:");
28    println!("    Rotation Threshold: {}", state.nt);
29    for (i, n) in state.n.iter().enumerate() {
30        println!("    [{}] {}", i, n);
31    }
32
33    if !state.b.is_empty() {
34        // Same summary as `kli status`.
35        let receipts = hab::receipt_count(&mut hby, alias, sn)?;
36        println!("  Witnesses:");
37        println!("    Count:\t\t{}", state.b.len());
38        println!("    Receipts:\t{}", receipts);
39        println!("    Threshold:\t{}", u64::from_str_radix(&state.bt, 16).unwrap_or(0));
40        for (i, w) in state.b.iter().enumerate() {
41            println!("    [{}] {}", i, w);
42        }
43    }
44
45    if !state.c.is_empty() {
46        println!("  Config: {:?}", state.c);
47    }
48
49    if !state.di.is_empty() {
50        println!("  Delegator: {}", state.di);
51    }
52
53    Ok(())
54}
55
56fn event_type_label(et: &str) -> &str {
57    match et {
58        "icp" => "Inception",
59        "rot" => "Rotation",
60        "ixn" => "Interaction",
61        "dip" => "Delegated Inception",
62        "drt" => "Delegated Rotation",
63        _ => et,
64    }
65}