Output identity details as JSON.
(&self, identity: &atomic_identity::Identity, is_default: bool)
| 165 | |
| 166 | /// Output identity details as JSON. |
| 167 | fn output_json(&self, identity: &atomic_identity::Identity, is_default: bool) { |
| 168 | use serde_json::json; |
| 169 | |
| 170 | let mut obj = json!({ |
| 171 | "name": identity.name, |
| 172 | "id": identity.id.to_base32(), |
| 173 | "type": super::format_identity_type(&identity.identity_type), |
| 174 | "usage": super::format_usage(&identity.usage), |
| 175 | "public_key": identity.public_key_base32(), |
| 176 | "is_default": is_default, |
| 177 | "created_at": identity.metadata.created_at.to_rfc3339(), |
| 178 | "is_expired": identity.is_expired(), |
| 179 | }); |
| 180 | |
| 181 | if let Some(email) = &identity.email { |
| 182 | obj["email"] = json!(email); |
| 183 | } |
| 184 | |
| 185 | if let Some(modified) = identity.metadata.modified_at { |
| 186 | obj["modified_at"] = json!(modified.to_rfc3339()); |
| 187 | } |
| 188 | |
| 189 | if let Some(expires) = identity.metadata.expires_at { |
| 190 | obj["expires_at"] = json!(expires.to_rfc3339()); |
| 191 | } |
| 192 | |
| 193 | if let Some(description) = &identity.metadata.description { |
| 194 | obj["description"] = json!(description); |
| 195 | } |
| 196 | |
| 197 | if let Some(delegated_by) = &identity.delegated_by { |
| 198 | obj["delegated_by"] = json!(delegated_by.to_base32()); |
| 199 | } |
| 200 | |
| 201 | println!("{}", serde_json::to_string_pretty(&obj).unwrap()); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | // Tests |