-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add logic for inspecting multi-manifest images
- Loading branch information
Showing
6 changed files
with
105 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use std::collections::HashMap; | ||
|
||
use miette::{bail, Report}; | ||
use serde::Deserialize; | ||
|
||
use crate::drivers::types::{ImageMetadata, Platform}; | ||
|
||
#[derive(Deserialize, Debug, Clone)] | ||
pub struct Metadata { | ||
manifest: Manifest, | ||
image: MetadataImage, | ||
} | ||
|
||
#[derive(Deserialize, Debug, Clone)] | ||
pub struct PlatformManifest { | ||
digest: String, | ||
platform: PlatformManifestInfo, | ||
} | ||
|
||
#[derive(Deserialize, Debug, Clone)] | ||
pub struct PlatformManifestInfo { | ||
architecture: String, | ||
} | ||
|
||
#[derive(Deserialize, Debug, Clone)] | ||
pub struct Manifest { | ||
digest: String, | ||
|
||
#[serde(default)] | ||
manifests: Vec<PlatformManifest>, | ||
} | ||
|
||
#[derive(Deserialize, Debug, Clone)] | ||
pub struct MetadataPlatformImage { | ||
config: Config, | ||
} | ||
|
||
#[derive(Deserialize, Debug, Clone)] | ||
#[serde(untagged)] | ||
pub enum MetadataImage { | ||
Single(MetadataPlatformImage), | ||
Multi(HashMap<String, MetadataPlatformImage>), | ||
} | ||
|
||
#[derive(Deserialize, Debug, Clone)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct Config { | ||
labels: HashMap<String, serde_json::Value>, | ||
} | ||
|
||
impl TryFrom<(Metadata, Platform)> for ImageMetadata { | ||
type Error = Report; | ||
|
||
fn try_from((metadata, platform): (Metadata, Platform)) -> Result<Self, Self::Error> { | ||
match metadata.image { | ||
MetadataImage::Single(image) => Ok(Self { | ||
labels: image.config.labels, | ||
digest: metadata.manifest.digest, | ||
}), | ||
MetadataImage::Multi(mut platforms) => { | ||
let Some(image) = platforms.remove(&platform.to_string()) else { | ||
bail!("Image information does not exist for {platform}"); | ||
}; | ||
let Some(manifest) = metadata | ||
.manifest | ||
.manifests | ||
.into_iter() | ||
.find(|manifest| manifest.platform.architecture == platform.arch()) | ||
else { | ||
bail!("Manifest does not exist for {platform}"); | ||
}; | ||
Ok(Self { | ||
labels: image.config.labels, | ||
digest: manifest.digest, | ||
}) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters