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)
| 388 | /// Returns [`CliError::Internal`] with an actionable message when the |
| 389 | /// identifier cannot be resolved (e.g. no matching identity on the server). |
| 390 | pub async fn resolve_identity(client: &StorageClient, identifier: &str) -> CliResult<uuid::Uuid> { |
| 391 | // 1. Try parsing as UUID first — zero network calls. |
| 392 | if let Ok(id) = uuid::Uuid::parse_str(identifier) { |
| 393 | return Ok(id); |
| 394 | } |
| 395 | |
| 396 | // 2. If it contains @, treat as email. |
| 397 | if identifier.contains('@') { |
| 398 | let info = client |
| 399 | .resolve_identity_by_email(identifier) |
| 400 | .await |
| 401 | .map_err(|e| { |
| 402 | if e.is_not_found() { |
| 403 | CliError::Internal(anyhow::anyhow!( |
| 404 | "No identity found with email '{}'.\n \ |
| 405 | The user must register first: atomic identity register <server-url>", |
| 406 | identifier |
| 407 | )) |
| 408 | } else { |
| 409 | CliError::RemoteError { |
| 410 | message: e.to_string(), |
| 411 | url: None, |
| 412 | } |
| 413 | } |
| 414 | })?; |
| 415 | log::debug!( |
| 416 | "Resolved email '{}' → {} ({})", |
| 417 | identifier, |
| 418 | info.id, |
| 419 | info.name |
| 420 | ); |
| 421 | return Ok(info.id); |
| 422 | } |
| 423 | |
| 424 | // 3. Otherwise, treat as identity name. |
| 425 | let info = client |
| 426 | .resolve_identity_by_name(identifier) |
| 427 | .await |
| 428 | .map_err(|e| { |
| 429 | if e.is_not_found() { |
| 430 | CliError::Internal(anyhow::anyhow!( |
| 431 | "No identity found with name '{}'.\n \ |
| 432 | The user must register first: atomic identity register <server-url>", |
| 433 | identifier |
| 434 | )) |
| 435 | } else { |
| 436 | CliError::RemoteError { |
| 437 | message: e.to_string(), |
| 438 | url: None, |
| 439 | } |
| 440 | } |
| 441 | })?; |
| 442 | log::debug!( |
| 443 | "Resolved name '{}' → {} ({})", |
| 444 | identifier, |
| 445 | info.id, |
| 446 | info.name |
| 447 | ); |
no test coverage detected