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

Function check_push_credentials

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

Verify, before a push begins, that the client can produce credentials for `remote_url`. Fails fast with an actionable error instead of letting the push proceed into a confusing 404 (which the server returns for private projects the caller isn't authorized to see). Returns `Ok(())` when an identity is resolvable (from `--identity`, the URL, or the default identity), exists in the local store, and

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

Source from the content-addressed store, hash-verified

554/// `--identity` explicitly names an identity that doesn't exist — that is a
555/// clear error, not a silent substitution.
556pub fn check_push_credentials(remote_url: &str, identity_override: Option<&str>) -> AuthResult<()> {
557 let store = IdentityStore::open_default()
558 .map_err(|e| AuthError::Internal(anyhow::anyhow!("Failed to open identity store: {e}")))?;
559
560 let inferred = resolve_identity_name_with_override(remote_url, identity_override);
561 let explicit = identity_override.is_some();
562
563 // Resolve a concrete identity, falling back to the default when the
564 // inferred name doesn't match (and the name didn't come from --identity).
565 let identity =
566 resolve_identity_with_default_fallback(&store, inferred.as_deref(), explicit, "push");
567 let resolved_name = identity.as_ref().map(|id| id.name.clone());
568
569 let issue = evaluate_push_credentials(
570 explicit,
571 inferred.as_deref(),
572 resolved_name.as_deref(),
573 |name| {
574 load_identity_lenient(&store, name)
575 .map(|id| store.load_keypair(&id.id, None).is_ok())
576 .unwrap_or(false)
577 },
578 );
579
580 match issue {
581 Some(issue) => Err(AuthError::AuthenticationFailed {
582 remote: format!("{remote_url}: {}", issue.message()),
583 }),
584 None => Ok(()),
585 }
586}
587
588/// Pure decision core for [`check_push_credentials`], split out so it can be
589/// unit-tested without touching the on-disk identity store.

Callers 3

pushFunction · 0.85
run_asyncMethod · 0.85
sync_credentialsMethod · 0.85

Calls 7

load_identity_lenientFunction · 0.85
as_refMethod · 0.80
load_keypairMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected