znippy-common/src/plugins/native/bundle.rs
//! What the airgap bundle handlers (`znippy-plugin-skidbladnir`,
//! `znippy-plugin-rust-toolchain`) share: the member row every one of them
//! writes, and the best-effort read of a JSON manifest member.
use std::collections::HashMap;
use crate::plugin::ExtensionValue;
/// Best-effort pull of a top-level string field from a JSON member. Never
/// panics — bad/garbage JSON just yields `None` (P-4).
pub fn json_str_field(data: &[u8], key: &str) -> Option<String> {
let v: serde_json::Value = serde_json::from_slice(data).ok()?;
v.get(key)?.as_str().map(str::to_string)
}
/// The three columns every bundle member carries: `member_kind`,
/// `logical_path` and (when the path names one) `component`.
pub fn member_row(kind: &str, path: &str, component: Option<String>) -> HashMap<String, ExtensionValue> {
let mut f = HashMap::new();
f.insert("member_kind".into(), ExtensionValue::Str(kind.into()));
f.insert("logical_path".into(), ExtensionValue::Str(path.into()));
if let Some(c) = component {
f.insert("component".into(), ExtensionValue::Str(c));
}
f
}