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

Function resolve_identity

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

290/// Returns [`CliError::Internal`] with an actionable message when the
291/// identifier cannot be resolved (e.g. no matching identity on the server).
292pub async fn resolve_identity(client: &StorageClient, identifier: &str) -> CliResult<uuid::Uuid> {
293 // 1. Try parsing as UUID first — zero network calls.
294 if let Ok(id) = uuid::Uuid::parse_str(identifier) {
295 return Ok(id);
296 }
297
298 // 2. If it contains @, treat as email.
299 if identifier.contains('@') {
300 let info = client
301 .resolve_identity_by_email(identifier)
302 .await
303 .map_err(|e| {
304 if e.is_not_found() {
305 CliError::Internal(anyhow::anyhow!(
306 "No identity found with email '{}'.\n \
307 The user must register first: atomic identity register <server-url>",
308 identifier
309 ))
310 } else {
311 CliError::RemoteError {
312 message: e.to_string(),
313 url: None,
314 }
315 }
316 })?;
317 log::debug!(
318 "Resolved email '{}' → {} ({})",
319 identifier,
320 info.id,
321 info.name
322 );
323 return Ok(info.id);
324 }
325
326 // 3. Otherwise, treat as identity name.
327 let info = client
328 .resolve_identity_by_name(identifier)
329 .await
330 .map_err(|e| {
331 if e.is_not_found() {
332 CliError::Internal(anyhow::anyhow!(
333 "No identity found with name '{}'.\n \
334 The user must register first: atomic identity register <server-url>",
335 identifier
336 ))
337 } else {
338 CliError::RemoteError {
339 message: e.to_string(),
340 url: None,
341 }
342 }
343 })?;
344 log::debug!(
345 "Resolved name '{}' → {} ({})",
346 identifier,
347 info.id,
348 info.name
349 );

Callers 2

executeMethod · 0.85
executeMethod · 0.85

Calls 4

containsMethod · 0.45
is_not_foundMethod · 0.45

Tested by

no test coverage detected