Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust/rpmostree-client: parse OCI deployment manifest #5266

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
rust/rpmostree-client: parse OCI deployment manifest
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
jbtrystram committed Jan 30, 2025
commit b0fb8b0d374fad4a810b1ccf9b82040c27434ee2
1 change: 1 addition & 0 deletions rust/rpmostree-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 17 additions & 1 deletion rust/rpmostree-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

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

@@ -97,6 +97,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)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be cleaner to do something like:

if let Some(serde_json::Value::String(inner))) {
            let manifest: oci_spec::image::ImageManifest = serde_json::from_str(&inner)?;
            return Ok(Some(manifest));
}

or so, this String::deserialize is duplicating the value unnecessarily.

let manifest: oci_spec::image::ImageManifest = serde_json::from_str(deser.as_str())?;

return Ok(Some(manifest));
};

Ok(None)
}
}

impl CliClient {
Loading