Skip to main content

detect_identity_collision_multi

Function detect_identity_collision_multi 

Source
pub fn detect_identity_collision_multi(
    self_pairs: &[(String, String)],
    self_name: &str,
    existing: &[ExistingIdentity],
) -> Option<CollisionHit>
Expand description

The N-pair generalization of detect_identity_collision: the candidate policy contributes one (identity, repo_key) pair per member repository (each identity resolved under THAT repository’s identityDefaults), and a collision is the FIRST pair that matches an existing pair. Loops the single-pair kernel, so N = 1 is exactly the old behavior.

use kopiur_api::validate::{detect_identity_collision_multi, CollisionHit, ExistingIdentity};

let existing = vec![ExistingIdentity {
    identity: "pg@billing:/pvc/data".into(),
    repo_key: "ClusterRepository/shared".into(),
    name: "billing/pg-a".into(),
}];
// The same identity in a DIFFERENT repository is fine; the pair that also
// lands in `ClusterRepository/shared` collides — and the hit names it.
let pairs = vec![
    ("pg@billing:/pvc/data".to_string(), "Repository/billing/nas".to_string()),
    ("pg@billing:/pvc/data".to_string(), "ClusterRepository/shared".to_string()),
];
assert_eq!(
    detect_identity_collision_multi(&pairs, "billing/pg-b", &existing),
    Some(CollisionHit {
        conflict: "billing/pg-a".into(),
        identity: "pg@billing:/pvc/data".into(),
        repo_key: "ClusterRepository/shared".into(),
    }),
);
// Disjoint repositories → no collision at all.
let disjoint = vec![("pg@billing:/pvc/data".to_string(), "Repository/billing/nas".to_string())];
assert_eq!(detect_identity_collision_multi(&disjoint, "billing/pg-b", &existing), None);