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

Function attach_identity

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

265/// unmodified and a debug log is emitted. This keeps push/pull/clone working
266/// against servers that don't require auth (e.g. public reads).
267pub async fn attach_identity(
268 config: HttpRemoteConfig,
269 remote_url: &str,
270 identity_override: Option<&str>,
271) -> HttpRemoteConfig {
272 if identity_override.is_some() {
273 log::debug!("Using explicit identity override: {:?}", identity_override);
274 }
275
276 // Priority 1: explicit override (--identity); 2/3: URL userinfo or subdomain.
277 let inferred = resolve_identity_name_with_override(remote_url, identity_override);
278 let source = if identity_override.is_some() {
279 format!("--identity {:?}", identity_override)
280 } else {
281 "URL/config inference".to_string()
282 };
283
284 let store = match IdentityStore::open_default() {
285 Ok(s) => s,
286 Err(e) => {
287 log::debug!("Failed to open identity store: {}", e);
288 return config;
289 }
290 };
291
292 // Resolve a concrete identity, falling back to the default when the
293 // inferred name doesn't match any local identity (e.g. the `aaron`
294 // subdomain vs. a local identity named `aaron-claude`). An explicit
295 // --identity that doesn't exist does NOT fall back (returns None → no
296 // auth header, so the server rejects it with a clear 401).
297 let explicit = identity_override.is_some();
298 let identity = match resolve_identity_with_default_fallback(
299 &store,
300 inferred.as_deref(),
301 explicit,
302 &source,
303 ) {
304 Some(id) => id,
305 None => {
306 log::debug!(
307 "No usable identity for {} (inferred={:?}) and no default set",
308 remote_url,
309 inferred
310 );
311 return config;
312 }
313 };
314
315 // Tokens are keyed to the apex server (where the identity registered), not
316 // the tenant subdomain — strip the leading subdomain label from the host.
317 let server = match apex_server_url(remote_url) {
318 Some(s) => s,
319 None => {
320 log::debug!("Could not derive apex server URL from: {}", remote_url);
321 return config;
322 }
323 };
324

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