(&self)
| 29 | |
| 30 | impl Command for Show { |
| 31 | fn run(&self) -> CliResult<()> { |
| 32 | let store = IdentityStore::open_default().map_err(|e| { |
| 33 | CliError::Internal(anyhow::anyhow!("Failed to open identity store: {e}")) |
| 34 | })?; |
| 35 | |
| 36 | let identity = store |
| 37 | .load_by_name(&self.name) |
| 38 | .map_err(|_| CliError::IdentityNotFound(self.name.clone()))?; |
| 39 | |
| 40 | if !identity.identity_type.is_delegated() && !identity.identity_type.is_agent() { |
| 41 | return Err(CliError::InvalidArgument { |
| 42 | message: format!( |
| 43 | "'{}' is not an agent identity.\n Use 'atomic identity show {}' instead.", |
| 44 | self.name, self.name |
| 45 | ), |
| 46 | }); |
| 47 | } |
| 48 | |
| 49 | let delegations = load_for_delegate(&store, &identity)?; |
| 50 | |
| 51 | if self.certificate { |
| 52 | let Some(newest) = delegations.first() else { |
| 53 | return Err(CliError::DelegationError { |
| 54 | message: format!("No certificate stored for '{}'", self.name), |
| 55 | }); |
| 56 | }; |
| 57 | println!( |
| 58 | "{}", |
| 59 | serde_json::to_string_pretty(&newest.document).unwrap() |
| 60 | ); |
| 61 | return Ok(()); |
| 62 | } |
| 63 | |
| 64 | println!("Agent: {}", identity.name); |
| 65 | println!(); |
| 66 | println!(" DID {}", identity.id.to_did()); |
| 67 | println!(" Key {}", identity.public_key.to_did_key()); |
| 68 | if let Some(email) = &identity.email { |
| 69 | println!(" Email {email}"); |
| 70 | } |
| 71 | println!( |
| 72 | " Type {}", |
| 73 | super::super::format_identity_type(&identity.identity_type) |
| 74 | ); |
| 75 | |
| 76 | if delegations.is_empty() { |
| 77 | println!(); |
| 78 | print_warning("No delegation certificate — this key can prove who it is, but is authorized for nothing."); |
| 79 | print_hint(&format!( |
| 80 | "Issue one: atomic identity delegate {}", |
| 81 | identity.name |
| 82 | )); |
| 83 | return Ok(()); |
| 84 | } |
| 85 | |
| 86 | let shown = if self.history { |
| 87 | &delegations[..] |
| 88 | } else { |
nothing calls this directly
no test coverage detected