Functional Weave
Code in Python

monitor.cert-check@1.0.0

impl/rust.rs

748 bytes · the Rust implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

use super::funejson::Value;  ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one

/// A certificate as one check behind a status page component. A warning
/// is work for the operator, not something a visitor notices, so it stays
/// up; critical is degraded because renewal is now urgent; an expired
/// certificate breaks every client, so it is down.
///
/// # Panics
/// Panics on an unknown state.
pub fn cert_check(state: &str) -> String {
    let status = match state {
        "ok" | "warning" => "up",
        "critical" => "degraded",
        "expired" => "down",
        other => panic!("unknown certificate state: {}", other),
    };
    status.to_string()
}

pub fn fune_vector(args: &[Value]) -> Value {
    let state = args[0].as_str().to_string();
    Value::str(&cert_check(&state))
}