diff --git a/hive-c0re/src/stores/power.rs b/hive-c0re/src/stores/power.rs index 63b89b8e..9d5bb708 100644 --- a/hive-c0re/src/stores/power.rs +++ b/hive-c0re/src/stores/power.rs @@ -38,13 +38,6 @@ pub enum Wanted { } impl Wanted { - /// Derived (`strum::EnumString`, the same `snake_case` convention - /// `as_str` uses) rather than a hand-written match kept in sync with - /// it by hand. - fn parse(s: &str) -> Option { - s.parse().ok() - } - /// Seed value from an observed running state (first boot after /// this store lands, or an agent spawned outside the normal path). pub fn from_running(running: bool) -> Self { @@ -121,7 +114,7 @@ impl PowerStore { .context("select agent_power")?; match row { None => Ok(None), - Some(stored) => Wanted::parse(&stored).map(Some).with_context(|| { + Some(stored) => stored.parse::().ok().map(Some).with_context(|| { format!("agent_power row for {agent} holds an unknown intent {stored:?}") }), } diff --git a/swarm-controller/src/webhook.rs b/swarm-controller/src/webhook.rs index b17cb222..3da6d8ae 100644 --- a/swarm-controller/src/webhook.rs +++ b/swarm-controller/src/webhook.rs @@ -218,17 +218,6 @@ impl DeliveryKind { <&str>::from(self) ) } - - /// Parse the `{kind}` path segment. Unknown values are rejected rather - /// than accepted-and-ignored: a typo in a registered `target_url` must - /// be *observable*, and a 200 for an unrecognised path is exactly the - /// silence this issue exists to remove. Derived (`strum::EnumString`, - /// the same per-variant `#[strum(serialize = "...")]` spellings - /// `as_str` uses) rather than a hand-written match kept in sync with - /// that one by hand. - fn parse(segment: &str) -> Option { - segment.parse().ok() - } } /// Why a delivery was refused. @@ -359,7 +348,10 @@ pub(super) async fn post_webhook_forge( return (refusal.status(), message).into_response(); } - let Some(kind) = DeliveryKind::parse(&kind) else { + // Unknown values are rejected rather than accepted-and-ignored: a typo in + // a registered `target_url` must be *observable*, and a 200 for an + // unrecognised path is exactly the silence this issue exists to remove. + let Some(kind) = kind.parse::().ok() else { tracing::warn!(%kind, "webhook: delivery on an unknown hook kind"); return (StatusCode::NOT_FOUND, "unknown hook kind").into_response(); }; @@ -547,20 +539,20 @@ mod tests { #[test] fn only_the_registered_hook_kinds_parse() { assert_eq!( - DeliveryKind::parse("knowledge"), + "knowledge".parse::().ok(), Some(DeliveryKind::Knowledge) ); assert_eq!( - DeliveryKind::parse("config-pr"), + "config-pr".parse::().ok(), Some(DeliveryKind::ConfigPr) ); assert_eq!( - DeliveryKind::parse("config_pr"), + "config_pr".parse::().ok(), None, "underscore is not the registered spelling; accepting both would make a journal line ambiguous" ); - assert_eq!(DeliveryKind::parse(""), None); - assert_eq!(DeliveryKind::parse("../knowledge"), None); + assert_eq!("".parse::().ok(), None); + assert_eq!("../knowledge".parse::().ok(), None); } /// A malformed stored secret is replaced rather than fatal — and the @@ -635,7 +627,7 @@ mod tests { let url = kind.target_url("https://swarm.example"); let segment = url.rsplit('/').next().expect("a last segment"); assert_eq!( - DeliveryKind::parse(segment), + segment.parse::().ok(), Some(kind), "the last path segment of a registered URL must parse back \ to the kind that built it"