cut off hives that left the roster: forge token, team seat, token secret, login role
This commit is contained in:
parent
f8a0388457
commit
11fec06a50
1 changed files with 830 additions and 21 deletions
|
|
@ -111,6 +111,32 @@ pub fn agents_from_role_names(names: &[String]) -> Vec<String> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
/// The hive that holds the cert-auth role or forge login `name`: the inverse
|
||||
/// of [`hive_object_name`], for a caller that needs the hives with a role.
|
||||
///
|
||||
/// `None` for an agent's object ([`AGENT_PREFIX`]), which shares the
|
||||
/// [`HIVE_PREFIX`] and is never a hive's, and for a name whose suffix is not a
|
||||
/// legal segment.
|
||||
#[must_use]
|
||||
pub fn hive_from_object_name(name: &str) -> Option<&str> {
|
||||
if name.starts_with(AGENT_PREFIX) {
|
||||
return None;
|
||||
}
|
||||
name.strip_prefix(HIVE_PREFIX)
|
||||
.filter(|hive| checked_segment("hive", hive).is_ok())
|
||||
}
|
||||
|
||||
/// The hives among `names`, a listing of cert-auth roles
|
||||
/// ([`hive_from_object_name`] for each).
|
||||
#[must_use]
|
||||
pub fn hives_from_role_names(names: &[String]) -> Vec<String> {
|
||||
names
|
||||
.iter()
|
||||
.filter_map(|name| hive_from_object_name(name))
|
||||
.map(str::to_owned)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// One read stanza. With [`list_stanza`], [`create_stanza`] and [`sign_stanza`],
|
||||
/// the only shapes this module emits, so what an agent may write is a property
|
||||
/// of the renderers rather than of each call site.
|
||||
|
|
@ -753,4 +779,26 @@ mod tests {
|
|||
let name = agent_object_name("atlas").expect("legal");
|
||||
assert_eq!(agents_from_role_names(&[name]), ["atlas"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_hive_roles_come_back_and_without_their_prefix() {
|
||||
let roles: Vec<String> = [
|
||||
"hive-pr1ma",
|
||||
"hive-agent-atlas",
|
||||
"swarm-controller",
|
||||
"hive-umbra",
|
||||
"hive-",
|
||||
"hive-a.b",
|
||||
]
|
||||
.map(str::to_owned)
|
||||
.to_vec();
|
||||
assert_eq!(hives_from_role_names(&roles), ["pr1ma", "umbra"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_hive_listing_inverts_hive_object_name() {
|
||||
let name = hive_object_name("pr1ma").expect("legal");
|
||||
assert_eq!(hive_from_object_name(&name), Some("pr1ma"));
|
||||
assert_eq!(hive_from_object_name("hive-agent-pr1ma"), None);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue