diff --git a/src/lib.rs b/src/lib.rs index d5df007..d8cd57e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,6 +51,8 @@ pub struct Arch { /// A specific platform (e.g. `aws`, `gcp`) #[derive(Debug, Deserialize)] pub struct Platform { + /// The release version number. + pub release: String, /// Specific formats. pub formats: HashMap<String, HashMap<String, Artifact>>, } @@ -176,6 +178,20 @@ impl Stream { .and_then(|p| p.get("disk")) } + /// Find a `disk` artifact with its version. + pub fn query_disk_and_version( + &self, + arch: &str, + artifact: &str, + format_name: &str, + ) -> Option<(&Artifact, &str)> { + let arch = self.architectures.get(arch)?; + let artifact = arch.artifacts.get(artifact)?; + let fmt = artifact.formats.get(format_name)?; + let disk = fmt.get("disk")?; + Some((disk, artifact.release.as_str())) + } + /// Find the single `disk` image for this architecture of the given type. Only use this /// for images which don't have multiple format.s pub fn query_thisarch_single(&self, artifact: &str) -> Option<&Artifact> { diff --git a/tests/it/main.rs b/tests/it/main.rs index 454e05b..d148bea 100644 --- a/tests/it/main.rs +++ b/tests/it/main.rs @@ -41,6 +41,17 @@ fn test_basic() { "2848b111a6917455686f38a3ce64d2321c33809b9cf796c5f6804b1c02d79d9d" ); + assert_eq!( + st.query_disk_and_version("x86_64", "metal", "raw.xz") + .as_ref() + .map(|(d, v)| (d.sha256.as_str(), *v)) + .unwrap(), + ( + "2848b111a6917455686f38a3ce64d2321c33809b9cf796c5f6804b1c02d79d9d", + "33.20201201.3.0" + ) + ); + assert_eq!( a.images .as_ref()