Skip to content

Commit 4e1e3cb

Browse files
authored
Merge pull request #917 from cgwalters/aleph-refactor
install: Factor out helper to create aleph version
2 parents 8d4bf5c + fd86d1d commit 4e1e3cb

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

lib/src/install.rs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,32 @@ impl FromStr for MountSpec {
496496
}
497497
}
498498

499+
impl InstallAleph {
500+
#[context("Creating aleph data")]
501+
pub(crate) fn new(
502+
src_imageref: &ostree_container::OstreeImageReference,
503+
imgstate: &ostree_container::store::LayeredImageState,
504+
selinux_state: &SELinuxFinalState,
505+
) -> Result<Self> {
506+
let uname = rustix::system::uname();
507+
let labels = crate::status::labels_of_config(&imgstate.configuration);
508+
let timestamp = labels
509+
.and_then(|l| {
510+
l.get(oci_spec::image::ANNOTATION_CREATED)
511+
.map(|s| s.as_str())
512+
})
513+
.and_then(crate::status::try_deserialize_timestamp);
514+
let r = InstallAleph {
515+
image: src_imageref.imgref.name.clone(),
516+
version: imgstate.version().as_ref().map(|s| s.to_string()),
517+
timestamp,
518+
kernel: uname.release().to_str()?.to_string(),
519+
selinux: selinux_state.to_aleph().to_string(),
520+
};
521+
Ok(r)
522+
}
523+
}
524+
499525
impl SourceInfo {
500526
// Inspect container information and convert it to an ostree image reference
501527
// that pulls from containers-storage.
@@ -804,23 +830,7 @@ async fn install_container(
804830
osconfig::inject_root_ssh_authorized_keys(&root, sepolicy, contents)?;
805831
}
806832

807-
let uname = rustix::system::uname();
808-
809-
let labels = crate::status::labels_of_config(&imgstate.configuration);
810-
let timestamp = labels
811-
.and_then(|l| {
812-
l.get(oci_spec::image::ANNOTATION_CREATED)
813-
.map(|s| s.as_str())
814-
})
815-
.and_then(crate::status::try_deserialize_timestamp);
816-
let aleph = InstallAleph {
817-
image: src_imageref.imgref.name.clone(),
818-
version: imgstate.version().as_ref().map(|s| s.to_string()),
819-
timestamp,
820-
kernel: uname.release().to_str()?.to_string(),
821-
selinux: state.selinux_state.to_aleph().to_string(),
822-
};
823-
833+
let aleph = InstallAleph::new(&src_imageref, &imgstate, &state.selinux_state)?;
824834
Ok((deployment, aleph))
825835
}
826836

0 commit comments

Comments
 (0)