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_clusterisNoneor""(no cluster identity configured): alwaysHostClass::Bare.- No
.inhostname:HostClass::Bare. - The part before the first
.is empty (e.g.".east"), or the part after is empty (e.g."ns."):HostClass::Barewith the whole hostname asnamespace— these aren’t well-formed<namespace>.<cluster>hostnames, so classification declines to guess which part is which. - The suffix (everything after the first
.) exactly equalsmy_cluster:HostClass::OwnCluster. - Otherwise:
HostClass::ForeignCluster— note"ns.east.x"under cluster"east"isForeignCluster { suffix: "east.x" }, notOwnCluster; 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" }
);