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

Function install_binding_refs

atomic-cli/src/commands/git/bootstrap.rs:197–303  ·  view source on GitHub ↗

The shared fail-closed binding install over an explicit ref-name list.

(
    repo: &Repository,
    git: &GitRepository,
    refs: Vec<String>,
)

Source from the content-addressed store, hash-verified

195
196/// The shared fail-closed binding install over an explicit ref-name list.
197fn install_binding_refs(
198 repo: &Repository,
199 git: &GitRepository,
200 refs: Vec<String>,
201) -> CliResult<usize> {
202 let mut installed = 0;
203 for ref_name in refs {
204 let target = git
205 .find_reference(&ref_name)
206 .map_err(|error| CliError::GitError {
207 message: format!("fetched binding ref '{ref_name}' is unreadable: {error}"),
208 })?
209 .target()
210 .ok_or_else(|| CliError::GitError {
211 message: format!("fetched binding ref '{ref_name}' has no direct target"),
212 })?;
213 let binding =
214 load_binding_at_ref(git, &ref_name, target).map_err(|error| CliError::GitError {
215 message: format!(
216 "fetched binding on '{ref_name}' is refused before installation: {error}"
217 ),
218 })?;
219 // The ref name must canonically claim the binding it carries: a
220 // re-shaped ref is not a valid publication surface. The degraded
221 // namespace ref name is verified against the DEGRADED layout by
222 // `binding_id_from_ref_name` for the primary namespace; degraded
223 // refs are re-shaped by construction, so the id is taken from the
224 // name and cross-checked with the payload id.
225 let id_from_ref =
226 if ref_name.starts_with(atomic_repository::git_binding::DEGRADED_HEAD_BINDING_PREFIX) {
227 atomic_repository::git_binding::binding_id_from_ref_name(&ref_name.replace(
228 atomic_repository::git_binding::DEGRADED_HEAD_BINDING_PREFIX,
229 atomic_repository::BINDING_REF_PREFIX,
230 ))
231 } else {
232 atomic_repository::git_binding::binding_id_from_ref_name(&ref_name)
233 }
234 .ok_or_else(|| CliError::GitError {
235 message: format!(
236 "fetched binding ref '{ref_name}' does not carry a binding id in a canonical \
237 <shard>/<id> layout and is refused before installation"
238 ),
239 })?;
240 if id_from_ref != binding.id() {
241 return Err(CliError::GitError {
242 message: format!(
243 "fetched binding ref '{ref_name}' carries binding {} but its ref name \
244 claims {id_from_ref}; mismatched ref ids are refused before installation",
245 binding.id()
246 ),
247 });
248 }
249 // Cryptography (structure + signature) and live-Git content
250 // verification before anything is stored: a tampered or malicious
251 // binding never reaches the immutable store.
252 atomic_repository::git_binding::verify_binding_cryptography(&binding).map_err(|error| {
253 CliError::GitError {
254 message: format!(

Callers 2

install_fetched_bindingsFunction · 0.85

Calls 9

binding_id_from_ref_nameFunction · 0.85
verify_binding_contentFunction · 0.85
store_bindingMethod · 0.80
load_binding_at_refFunction · 0.70
replaceMethod · 0.45
idMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected