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

Function resolve_identity

atomic-cli/src/commands/client.rs:365–424  ·  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

363/// Returns [`CliError::Internal`] with an actionable message when the
364/// identifier cannot be resolved (e.g. no matching identity on the server).
365pub async fn resolve_identity(client: &StorageClient, identifier: &str) -> CliResult<uuid::Uuid> {
366 // 1. Try parsing as UUID first — zero network calls.
367 if let Ok(id) = uuid::Uuid::parse_str(identifier) {
368 return Ok(id);
369 }
370
371 // 2. If it contains @, treat as email.
372 if identifier.contains('@') {
373 let info = client
374 .resolve_identity_by_email(identifier)
375 .await
376 .map_err(|e| {
377 if e.is_not_found() {
378 CliError::Internal(anyhow::anyhow!(
379 "No identity found with email '{}'.\n \
380 The user must register first: atomic identity register <server-url>",
381 identifier
382 ))
383 } else {
384 CliError::RemoteError {
385 message: e.to_string(),
386 url: None,
387 }
388 }
389 })?;
390 log::debug!(
391 "Resolved email '{}' → {} ({})",
392 identifier,
393 info.id,
394 info.name
395 );
396 return Ok(info.id);
397 }
398
399 // 3. Otherwise, treat as identity name.
400 let info = client
401 .resolve_identity_by_name(identifier)
402 .await
403 .map_err(|e| {
404 if e.is_not_found() {
405 CliError::Internal(anyhow::anyhow!(
406 "No identity found with name '{}'.\n \
407 The user must register first: atomic identity register <server-url>",
408 identifier
409 ))
410 } else {
411 CliError::RemoteError {
412 message: e.to_string(),
413 url: None,
414 }
415 }
416 })?;
417 log::debug!(
418 "Resolved name '{}' → {} ({})",
419 identifier,
420 info.id,
421 info.name
422 );

Callers 2

executeMethod · 0.85
executeMethod · 0.85

Calls 4

containsMethod · 0.45
is_not_foundMethod · 0.45

Tested by

no test coverage detected