(&self)
| 27 | |
| 28 | impl Command for List { |
| 29 | fn run(&self) -> CliResult<()> { |
| 30 | let store = IdentityStore::open_default().map_err(|e| { |
| 31 | CliError::Internal(anyhow::anyhow!("Failed to open identity store: {e}")) |
| 32 | })?; |
| 33 | |
| 34 | let identities = store |
| 35 | .list() |
| 36 | .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to list identities: {e}")))?; |
| 37 | |
| 38 | let mut rows = Vec::new(); |
| 39 | for identity in identities { |
| 40 | if !matches!( |
| 41 | identity.identity_type, |
| 42 | IdentityType::Agent | IdentityType::Delegated |
| 43 | ) { |
| 44 | continue; |
| 45 | } |
| 46 | // The freshest certificate is the one that governs; older ones are |
| 47 | // history and would only add noise to a list. |
| 48 | let newest = load_for_delegate(&store, &identity)?.into_iter().next(); |
| 49 | let status = newest |
| 50 | .as_ref() |
| 51 | .map(|d| d.status) |
| 52 | .unwrap_or(DelegationStatus::Revoked); |
| 53 | |
| 54 | if !self.include_expired && status != DelegationStatus::Active { |
| 55 | continue; |
| 56 | } |
| 57 | rows.push((identity, newest, status)); |
| 58 | } |
| 59 | |
| 60 | if self.json { |
| 61 | let payload: Vec<_> = rows |
| 62 | .iter() |
| 63 | .map(|(identity, delegation, status)| { |
| 64 | json!({ |
| 65 | "name": identity.name, |
| 66 | "did": identity.id.to_did(), |
| 67 | "publicKey": identity.public_key.to_did_key(), |
| 68 | "type": super::super::format_identity_type(&identity.identity_type), |
| 69 | "status": status.to_string(), |
| 70 | "delegation": delegation.as_ref().map(describe_delegation), |
| 71 | }) |
| 72 | }) |
| 73 | .collect(); |
| 74 | println!("{}", serde_json::to_string_pretty(&payload).unwrap()); |
| 75 | return Ok(()); |
| 76 | } |
| 77 | |
| 78 | if rows.is_empty() { |
| 79 | if self.include_expired { |
| 80 | println!("No agent identities."); |
| 81 | } else { |
| 82 | println!("No active agent identities."); |
| 83 | print_hint("Use --include-expired to see withdrawn or lapsed ones"); |
| 84 | } |
| 85 | println!(); |
| 86 | println!( |
nothing calls this directly
no test coverage detected