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

Function resolve_identity_with_default_fallback

atomic-remote/src/auth/mod.rs:283–320  ·  view source on GitHub ↗

Resolve a concrete identity for a remote operation, falling back to the default identity when the inferred name doesn't match any local identity. This is the single place that bridges name resolution (URL subdomain, server binding, `--identity` flag) and the on-disk identity store. The fallback to the default identity makes the common case "just work": a user with a single registered identity can

(
    store: &IdentityStore,
    inferred_name: Option<&str>,
    explicit: bool,
    inferred_source: &str,
)

Source from the content-addressed store, hash-verified

281/// `inferred_source` labels the resolution path in debug logs (e.g.
282/// `"subdomain 'aaron'"`, `"--identity 'aaron-claude'"`).
283fn resolve_identity_with_default_fallback(
284 store: &IdentityStore,
285 inferred_name: Option<&str>,
286 explicit: bool,
287 inferred_source: &str,
288) -> Option<Identity> {
289 let resolved_name = decide_identity_with_default_fallback(
290 inferred_name,
291 explicit,
292 |name| load_identity_lenient(store, name).is_some(),
293 store.get_default().ok().flatten().map(|id| id.name.clone()),
294 );
295
296 match resolved_name.as_deref() {
297 Some(name) if inferred_name == Some(name) => {
298 log::debug!("Resolved identity '{name}' via {inferred_source}");
299 }
300 Some(name) => {
301 log::debug!("Falling back to default identity '{name}'");
302 }
303 None => {
304 if explicit {
305 log::debug!(
306 "Explicit identity {:?} ({inferred_source}) not found; \
307 not falling back to default",
308 inferred_name
309 );
310 } else {
311 log::debug!(
312 "No usable identity for {inferred_source} \
313 (inferred={inferred_name:?}) and no default set"
314 );
315 }
316 }
317 }
318
319 resolved_name.and_then(|name| load_identity_lenient(store, &name))
320}
321
322/// Pure decision core for identity resolution with a default fallback.
323///

Callers 2

attach_identityFunction · 0.85
check_push_credentialsFunction · 0.85

Calls 5

load_identity_lenientFunction · 0.85
okMethod · 0.45
get_defaultMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected