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

Function attach_identity

atomic-cli/src/commands/auth.rs:314–386  ·  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

312/// unmodified and a debug log is emitted. This keeps push/pull/clone working
313/// against servers that don't require auth (e.g. public reads).
314pub async fn attach_identity(
315 config: HttpRemoteConfig,
316 remote_url: &str,
317 identity_override: Option<&str>,
318) -> HttpRemoteConfig {
319 if identity_override.is_some() {
320 log::debug!("Using explicit identity override: {:?}", identity_override);
321 }
322
323 // Priority 1: explicit override (--identity); 2/3: URL userinfo or subdomain.
324 let inferred = resolve_identity_name_with_override(remote_url, identity_override);
325 let source = if identity_override.is_some() {
326 format!("--identity {:?}", identity_override)
327 } else {
328 "URL/config inference".to_string()
329 };
330
331 let store = match IdentityStore::open_default() {
332 Ok(s) => s,
333 Err(e) => {
334 log::debug!("Failed to open identity store: {}", e);
335 return config;
336 }
337 };
338
339 // Resolve a concrete identity, falling back to the default when the
340 // inferred name doesn't match any local identity (e.g. the `aaron`
341 // subdomain vs. a local identity named `aaron-claude`). An explicit
342 // --identity that doesn't exist does NOT fall back (returns None → no
343 // auth header, so the server rejects it with a clear 401).
344 let explicit = identity_override.is_some();
345 let identity = match resolve_identity_with_default_fallback(
346 &store,
347 inferred.as_deref(),
348 explicit,
349 &source,
350 ) {
351 Some(id) => id,
352 None => {
353 log::debug!(
354 "No usable identity for {} (inferred={:?}) and no default set",
355 remote_url,
356 inferred
357 );
358 return config;
359 }
360 };
361
362 // Tokens are keyed to the apex server (where the identity registered), not
363 // the tenant subdomain — strip the leading subdomain label from the host.
364 let server = match apex_server_url(remote_url) {
365 Some(s) => s,
366 None => {
367 log::debug!("Could not derive apex server URL from: {}", remote_url);
368 return config;
369 }
370 };
371

Callers 4

build_remote_configMethod · 0.85
build_remote_configMethod · 0.85
run_remoteMethod · 0.85
build_remote_configMethod · 0.85

Calls 6

apex_server_urlFunction · 0.85
get_tokenFunction · 0.85
cloneMethod · 0.45
with_headerMethod · 0.45

Tested by

no test coverage detected