Skip to main content

opensession_api/
deploy.rs

1//! Deployment profile flags shared by server and worker runtimes.
2
3/// Env var controlling anonymous public feed listing on the Axum server.
4pub const ENV_PUBLIC_FEED_ENABLED: &str = "OPENSESSION_PUBLIC_FEED_ENABLED";
5
6/// Env var controlling whether team APIs are mounted on the Worker runtime.
7pub const ENV_TEAM_API_ENABLED: &str = "ENABLE_TEAM_API";
8
9/// Env var selecting the session score plugin used during upload.
10pub const ENV_SESSION_SCORE_PLUGIN: &str = "OPENSESSION_SESSION_SCORE_PLUGIN";
11
12/// Parse a human-friendly boolean env flag value.
13///
14/// Accepted truthy values:
15/// - `1`
16/// - `true`
17/// - `yes`
18/// - `on`
19pub fn parse_bool_flag(raw: Option<&str>, default: bool) -> bool {
20    raw.map(|value| {
21        matches!(
22            value.trim().to_ascii_lowercase().as_str(),
23            "1" | "true" | "yes" | "on"
24        )
25    })
26    .unwrap_or(default)
27}
28
29#[cfg(test)]
30mod tests {
31    use super::parse_bool_flag;
32
33    #[test]
34    fn parses_truthy_values() {
35        for value in ["1", "true", "TRUE", "yes", "on"] {
36            assert!(parse_bool_flag(Some(value), false));
37        }
38    }
39
40    #[test]
41    fn parses_falsy_values() {
42        for value in ["0", "false", "no", "off", ""] {
43            assert!(!parse_bool_flag(Some(value), true));
44        }
45    }
46
47    #[test]
48    fn uses_default_for_missing_value() {
49        assert!(parse_bool_flag(None, true));
50        assert!(!parse_bool_flag(None, false));
51    }
52}