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

Function attach_identity

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

Attach a Bearer JWT auth header to the remote config. `identity_override` — if provided, this identity name is used directly, bypassing URL-based inference. Set from `RemoteEntry.identity` or the `--identity` CLI flag. If the identity cannot be resolved (no override, no userinfo, no subdomain, or identity not found in the store) or login fails, the config is returned unmodified and a debug log i

(
    config: HttpRemoteConfig,
    remote_url: &str,
    identity_override: Option<&str>,
)

Source from the content-addressed store, hash-verified

364/// unmodified and a debug log is emitted. This keeps push/pull/clone working
365/// against servers that don't require auth (e.g. public reads).
366pub async fn attach_identity(
367 config: HttpRemoteConfig,
368 remote_url: &str,
369 identity_override: Option<&str>,
370) -> HttpRemoteConfig {
371 if identity_override.is_some() {
372 log::debug!("Using explicit identity override: {:?}", identity_override);
373 }
374
375 // Priority 1: explicit override (--identity); 2/3: URL userinfo or subdomain.
376 let inferred = resolve_identity_name_with_override(remote_url, identity_override);
377 let source = if identity_override.is_some() {
378 format!("--identity {:?}", identity_override)
379 } else {
380 "URL/config inference".to_string()
381 };
382
383 let store = match IdentityStore::open_default() {
384 Ok(s) => s,
385 Err(e) => {
386 log::debug!("Failed to open identity store: {}", e);
387 return config;
388 }
389 };
390
391 // Resolve a concrete identity, falling back to the default when the
392 // inferred name doesn't match any local identity (e.g. the `aaron`
393 // subdomain vs. a local identity named `aaron-claude`). An explicit
394 // --identity that doesn't exist does NOT fall back (returns None → no
395 // auth header, so the server rejects it with a clear 401).
396 let explicit = identity_override.is_some();
397 let identity = match resolve_identity_with_default_fallback(
398 &store,
399 inferred.as_deref(),
400 explicit,
401 &source,
402 ) {
403 Some(id) => id,
404 None => {
405 log::debug!(
406 "No usable identity for {} (inferred={:?}) and no default set",
407 remote_url,
408 inferred
409 );
410 return config;
411 }
412 };
413
414 // Tokens are keyed to the apex server (where the identity registered), not
415 // the tenant subdomain — strip the leading subdomain label from the host.
416 let server = match apex_server_url(remote_url) {
417 Some(s) => s,
418 None => {
419 log::debug!("Could not derive apex server URL from: {}", remote_url);
420 return config;
421 }
422 };
423

Callers 7

sync_auth_headersFunction · 0.85
adoptMethod · 0.85
build_remote_configMethod · 0.85
build_remote_configMethod · 0.85
run_remoteMethod · 0.85
build_remote_configMethod · 0.85
sync_credentialsMethod · 0.85

Calls 7

get_tokenFunction · 0.85
delegation_headerFunction · 0.85
apex_server_urlFunction · 0.70
cloneMethod · 0.45
with_headerMethod · 0.45

Tested by

no test coverage detected