Resolve a flexible identity reference to a UUID. Accepts: - A UUID string (passed through directly) - An email address (contains `@` — resolved via server) - An identity name (resolved via server) # Errors Returns [`CliError::Internal`] with an actionable message when the identifier cannot be resolved (e.g. no matching identity on the server).
(client: &StorageClient, identifier: &str)
| 460 | /// Returns [`CliError::Internal`] with an actionable message when the |
| 461 | /// identifier cannot be resolved (e.g. no matching identity on the server). |
| 462 | pub async fn resolve_identity(client: &StorageClient, identifier: &str) -> CliResult<uuid::Uuid> { |
| 463 | // 1. Try parsing as UUID first — zero network calls. |
| 464 | if let Ok(id) = uuid::Uuid::parse_str(identifier) { |
| 465 | return Ok(id); |
| 466 | } |
| 467 | |
| 468 | // 2. If it contains @, treat as email. |
| 469 | if identifier.contains('@') { |
| 470 | let info = client |
| 471 | .resolve_identity_by_email(identifier) |
| 472 | .await |
| 473 | .map_err(|e| { |
| 474 | if e.is_not_found() { |
| 475 | CliError::Internal(anyhow::anyhow!( |
| 476 | "No identity found with email '{}'.\n \ |
| 477 | The user must register first: atomic identity register <server-url>", |
| 478 | identifier |
| 479 | )) |
| 480 | } else { |
| 481 | CliError::RemoteError { |
| 482 | message: e.to_string(), |
| 483 | url: None, |
| 484 | } |
| 485 | } |
| 486 | })?; |
| 487 | log::debug!( |
| 488 | "Resolved email '{}' → {} ({})", |
| 489 | identifier, |
| 490 | info.id, |
| 491 | info.name |
| 492 | ); |
| 493 | return Ok(info.id); |
| 494 | } |
| 495 | |
| 496 | // 3. Otherwise, treat as identity name. |
| 497 | let info = client |
| 498 | .resolve_identity_by_name(identifier) |
| 499 | .await |
| 500 | .map_err(|e| { |
| 501 | if e.is_not_found() { |
| 502 | CliError::Internal(anyhow::anyhow!( |
| 503 | "No identity found with name '{}'.\n \ |
| 504 | The user must register first: atomic identity register <server-url>", |
| 505 | identifier |
| 506 | )) |
| 507 | } else { |
| 508 | CliError::RemoteError { |
| 509 | message: e.to_string(), |
| 510 | url: None, |
| 511 | } |
| 512 | } |
| 513 | })?; |
| 514 | log::debug!( |
| 515 | "Resolved name '{}' → {} ({})", |
| 516 | identifier, |
| 517 | info.id, |
| 518 | info.name |
| 519 | ); |
no test coverage detected