coreos_stream_metadata/
rhcos.rs

1//! APIs for interacting specifically with RHEL CoreOS
2
3use strum_macros::{Display, EnumString};
4
5const INSTALLER_GIT: &str = "https://raw.githubusercontent.com/openshift/installer/";
6const LEGACY_PATH: &str = "/data/data/rhcos-stream.json";
7const PATH: &str = "/data/data/coreos/rhcos.json";
8
9/// Well-known streams for RHEL CoreOS.
10///
11/// These map to OpenShift versions.  Only >= 4.8 has stream metadata.
12#[derive(Debug, PartialEq, Eq, Clone, Copy, EnumString, Display)]
13pub enum StreamID {
14    /// 4.8
15    #[strum(serialize = "4.8")]
16    FourEight,
17    /// 4.9
18    #[strum(serialize = "4.9")]
19    FourNine,
20    /// 4.10
21    #[strum(serialize = "4.10")]
22    FourTen,
23}
24
25impl StreamID {
26    /// Return the URL for this stream.
27    pub fn url(&self) -> String {
28        let (path, branchname) = match self {
29            StreamID::FourEight => (LEGACY_PATH, "release-4.8"),
30            StreamID::FourNine => (LEGACY_PATH, "release-4.9"),
31            StreamID::FourTen => (PATH, "release-4.10"),
32        };
33        format!("{}{}{}", INSTALLER_GIT, branchname, path)
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40    use std::str::FromStr;
41
42    #[test]
43    fn test_rhcos_streamid() {
44        assert_eq!(StreamID::FourEight.to_string(), "4.8");
45        assert_eq!(StreamID::FourNine.to_string(), "4.9");
46        assert_eq!(StreamID::FourTen.to_string(), "4.10");
47
48        assert_eq!(StreamID::from_str("4.8").unwrap(), StreamID::FourEight);
49        assert_eq!(StreamID::from_str("4.9").unwrap(), StreamID::FourNine);
50        assert_eq!(StreamID::from_str("4.10").unwrap(), StreamID::FourTen);
51        assert!(StreamID::from_str("foo").is_err());
52
53        assert_eq!(StreamID::FourEight.url(), "https://raw.githubusercontent.com/openshift/installer/release-4.8/data/data/rhcos-stream.json");
54        assert_eq!(StreamID::FourNine.url(), "https://raw.githubusercontent.com/openshift/installer/release-4.9/data/data/rhcos-stream.json");
55        assert_eq!(StreamID::FourTen.url(), "https://raw.githubusercontent.com/openshift/installer/release-4.10/data/data/coreos/rhcos.json");
56    }
57}