lockfile: Allow metadata
field in locked packages
This field will allow humans to shove additional structured metadata into lockfiles which could then be used by higher-level tools. See: https://github.com/coreos/fedora-coreos-config/pull/965
This commit is contained in:
parent
771361d59b
commit
ffb8353b11
@ -129,10 +129,14 @@ enum LockedPackage {
|
|||||||
Evr {
|
Evr {
|
||||||
evr: String,
|
evr: String,
|
||||||
digest: Option<String>,
|
digest: Option<String>,
|
||||||
|
#[serde(skip_serializing)]
|
||||||
|
metadata: Option<BTreeMap<String, serde_json::Value>>,
|
||||||
},
|
},
|
||||||
Evra {
|
Evra {
|
||||||
evra: String,
|
evra: String,
|
||||||
digest: Option<String>,
|
digest: Option<String>,
|
||||||
|
#[serde(skip_serializing)]
|
||||||
|
metadata: Option<BTreeMap<String, serde_json::Value>>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,13 +165,13 @@ impl LockfileConfig {
|
|||||||
.iter()
|
.iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
.map(|(k, v)| match v {
|
.map(|(k, v)| match v {
|
||||||
LockedPackage::Evr { evr, digest } => Ok(crate::ffi::LockedPackage {
|
LockedPackage::Evr { evr, digest, .. } => Ok(crate::ffi::LockedPackage {
|
||||||
name: k.clone(),
|
name: k.clone(),
|
||||||
evr: evr.clone(),
|
evr: evr.clone(),
|
||||||
arch: "".into(),
|
arch: "".into(),
|
||||||
digest: digest.clone().unwrap_or_default(),
|
digest: digest.clone().unwrap_or_default(),
|
||||||
}),
|
}),
|
||||||
LockedPackage::Evra { evra, digest } => {
|
LockedPackage::Evra { evra, digest, .. } => {
|
||||||
let evr_arch: Vec<&str> = evra.rsplitn(2, '.').collect();
|
let evr_arch: Vec<&str> = evra.rsplitn(2, '.').collect();
|
||||||
if evr_arch.len() != 2 {
|
if evr_arch.len() != 2 {
|
||||||
Err(anyhow!("package {} has malformed evra: {}", k, evra).into())
|
Err(anyhow!("package {} has malformed evra: {}", k, evra).into())
|
||||||
@ -212,10 +216,15 @@ mod tests {
|
|||||||
},
|
},
|
||||||
"bar": {
|
"bar": {
|
||||||
"evra": "0.8-15.x86_64",
|
"evra": "0.8-15.x86_64",
|
||||||
"digest": "sha256:cafedead"
|
"digest": "sha256:cafedead",
|
||||||
|
"metadata": {
|
||||||
|
"foo": true,
|
||||||
|
"bar": "baz"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"baz": {
|
"baz": {
|
||||||
"evr": "2.1.1-1"
|
"evr": "2.1.1-1",
|
||||||
|
"metadata": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"source-packages": {
|
"source-packages": {
|
||||||
@ -227,14 +236,14 @@ mod tests {
|
|||||||
|
|
||||||
fn assert_evra(locked_package: &LockedPackage, expected_evra: &str) {
|
fn assert_evra(locked_package: &LockedPackage, expected_evra: &str) {
|
||||||
match locked_package {
|
match locked_package {
|
||||||
LockedPackage::Evra { evra, digest: _ } => assert_eq!(evra, expected_evra),
|
LockedPackage::Evra { evra, .. } => assert_eq!(evra, expected_evra),
|
||||||
_ => panic!("Expected LockedPackage::Evra variant"),
|
_ => panic!("Expected LockedPackage::Evra variant"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assert_evr(locked_package: &LockedPackage, expected_evr: &str) {
|
fn assert_evr(locked_package: &LockedPackage, expected_evr: &str) {
|
||||||
match locked_package {
|
match locked_package {
|
||||||
LockedPackage::Evr { evr, digest: _ } => assert_eq!(evr, expected_evr),
|
LockedPackage::Evr { evr, .. } => assert_eq!(evr, expected_evr),
|
||||||
_ => panic!("Expected LockedPackage::Evr variant"),
|
_ => panic!("Expected LockedPackage::Evr variant"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -370,6 +379,7 @@ pub(crate) fn lockfile_write(
|
|||||||
LockedPackage::Evra {
|
LockedPackage::Evra {
|
||||||
evra: format!("{}.{}", evr.as_str(), arch.as_str()),
|
evra: format!("{}.{}", evr.as_str(), arch.as_str()),
|
||||||
digest: Some(chksum),
|
digest: Some(chksum),
|
||||||
|
metadata: None,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user