Skip to content

Commit

Permalink
rust/rpmostree-client: parse OCI deployment manifest
Browse files Browse the repository at this point in the history
When the deployment is an OCI image, the base_commit_meta
field contains nested escaped JSON.

Add a method to get the base oci manifest deserialized into an
ImageManifest from the oci-spec rust crate.

Fixes #5196
  • Loading branch information
jbtrystram committed Jan 30, 2025
1 parent 0b11110 commit 17dca97
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
1 change: 1 addition & 0 deletions rust/rpmostree-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ publish = false

[dependencies]
anyhow = "1.0.94"
oci-spec = "0.7.1"
serde = { version = "1.0.217", features = ["derive"] }
serde_derive = "1.0.118"
serde_json = "1.0.135"
19 changes: 18 additions & 1 deletion rust/rpmostree-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use anyhow::Context;
use serde_derive::Deserialize;
use oci_spec;
use serde::Deserialize;
use std::collections::HashMap;
use std::process::Command;

Expand Down Expand Up @@ -97,6 +98,22 @@ impl Deployment {
Err(format!("No {} metadata key", k).into())
}
}

pub fn get_base_manifest(&self) -> Result<Option<oci_spec::image::ImageManifest>> {
if self.container_image_reference.is_none() {
return Ok(None);
}

let manifest = self.base_commit_meta.get("ostree.manifest");
if let Some(inner) = manifest {
let deser = String::deserialize(inner)?;
let manifest: oci_spec::image::ImageManifest = serde_json::from_str(deser.as_str())?;

return Ok(Some(manifest));
};

Ok(None)
}
}

impl CliClient {
Expand Down
Loading

0 comments on commit 17dca97

Please sign in to comment.