client: Add API to fetch base commit metadata
Also desired by Zincati.
This commit is contained in:
parent
5b647af14a
commit
8f77970683
@ -76,6 +76,25 @@ impl Deployment {
|
||||
.as_deref()
|
||||
.unwrap_or(self.checksum.as_str())
|
||||
}
|
||||
|
||||
/// Find a given metadata key in the base commit, which must hold a non-empty string.
|
||||
pub fn find_base_commitmeta_string<'a>(&'a self, k: &str) -> Result<&'a str> {
|
||||
let v = self.base_commit_meta.get(k);
|
||||
if let Some(v) = v {
|
||||
match v {
|
||||
serde_json::Value::String(v) => {
|
||||
if v.is_empty() {
|
||||
Err(format!("Invalid empty {} metadata key", k).into())
|
||||
} else {
|
||||
Ok(v)
|
||||
}
|
||||
}
|
||||
_ => Err(format!("Invalid non-string {} metadata key", k).into()),
|
||||
}
|
||||
} else {
|
||||
Err(format!("No {} metadata key", k).into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn cli_cmd(c: &CliClient) -> Command {
|
||||
|
@ -13,5 +13,12 @@ fn parse_workstation() -> Result<()> {
|
||||
booted.get_base_commit(),
|
||||
"229387d3c0bb8ad698228ca5702eca72aed8b298a7c800be1dc72bab160a9f7f"
|
||||
);
|
||||
assert!(booted.find_base_commitmeta_string("foo").is_err());
|
||||
assert_eq!(
|
||||
booted
|
||||
.find_base_commitmeta_string("coreos-assembler.config-gitrev")
|
||||
.unwrap(),
|
||||
"80966f951c766846da070b4c168b9170c61513e2"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user