Skip to main content

classify_hostname

Function classify_hostname 

Source
pub fn classify_hostname<'a>(
    hostname: &'a str,
    my_cluster: Option<&str>,
) -> HostClass<'a>
Expand description

Classify a kopia identity hostname against my_cluster (IdentityDefaults::cluster, resolved from the consuming repository), so a reader (retention pruning, discovered-Snapshot placement) can tell whether a hostname it sees was written by this cluster, another cluster sharing the same repository, or predates cluster identity entirely.

Total and pure — never panics, never fabricates an empty namespace:

  • my_cluster is None or "" (no cluster identity configured): always HostClass::Bare.
  • No . in hostname: HostClass::Bare.
  • The part before the first . is empty (e.g. ".east"), or the part after is empty (e.g. "ns."): HostClass::Bare with the whole hostname as namespace — these aren’t well-formed <namespace>.<cluster> hostnames, so classification declines to guess which part is which.
  • The suffix (everything after the first .) exactly equals my_cluster: HostClass::OwnCluster.
  • Otherwise: HostClass::ForeignCluster — note "ns.east.x" under cluster "east" is ForeignCluster { suffix: "east.x" }, not OwnCluster; only an exact suffix match is ours.
use kopiur_api::identity::{HostClass, classify_hostname};

assert_eq!(
    classify_hostname("billing.east", Some("east")),
    HostClass::OwnCluster { namespace: "billing" }
);
assert_eq!(
    classify_hostname("billing.west", Some("east")),
    HostClass::ForeignCluster { suffix: "west" }
);
// No cluster identity configured => every hostname reads as legacy/bare.
assert_eq!(
    classify_hostname("billing.east", None),
    HostClass::Bare { namespace: "billing.east" }
);