MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / resolve_identity

Function resolve_identity

atomic-cli/src/commands/client.rs:463–522  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 2

executeMethod · 0.85
executeMethod · 0.85

Calls 4

containsMethod · 0.45
is_not_foundMethod · 0.45

Tested by

no test coverage detected