From 8a8a5cd622198825372879c7f97e276190459768 Mon Sep 17 00:00:00 2001 From: Manuel Fuchs Date: Thu, 15 Feb 2024 11:06:37 +0100 Subject: [PATCH] Expose overwrite_layer_sboms in BuildContext --- libcnb/src/build.rs | 9 +++++++++ libcnb/src/error.rs | 3 +++ libcnb/src/layer/handling.rs | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libcnb/src/build.rs b/libcnb/src/build.rs index 65bed2b3..be96fc16 100644 --- a/libcnb/src/build.rs +++ b/libcnb/src/build.rs @@ -140,6 +140,15 @@ impl BuildContext { ) .map_err(crate::Error::OverwriteLayerExecdError) } + + pub fn overwrite_layer_sboms( + &self, + layer_name: impl AsRef, + sboms: &[Sbom], + ) -> crate::Result<(), B::Error> { + crate::layer::overwrite_layer_sboms(&self.layers_dir, layer_name.as_ref(), sboms) + .map_err(crate::Error::OverwriteLayerSbomsError) + } } /// Describes the result of the build phase. diff --git a/libcnb/src/error.rs b/libcnb/src/error.rs index dfc8e02b..920673b8 100644 --- a/libcnb/src/error.rs +++ b/libcnb/src/error.rs @@ -23,6 +23,9 @@ pub enum Error { #[error("Couldn't write exec.d programs to layer: {0}")] OverwriteLayerExecdError(#[from] OverwriteLayerExecdError), + #[error("Couldn't write sboms to layer: {0}")] + OverwriteLayerSbomsError(#[from] std::io::Error), + #[error("Process type error: {0}")] ProcessTypeError(#[from] ProcessTypeError), diff --git a/libcnb/src/layer/handling.rs b/libcnb/src/layer/handling.rs index a28c7045..1e838b03 100644 --- a/libcnb/src/layer/handling.rs +++ b/libcnb/src/layer/handling.rs @@ -280,7 +280,7 @@ pub(crate) fn delete_layer>( Ok(()) } -fn write_layer_sboms>( +pub(crate) fn overwrite_layer_sboms>( layers_dir: P, layer_name: &LayerName, sboms: &[Sbom], @@ -353,7 +353,7 @@ fn write_layer>( write_toml_file(&layer_content_metadata, layer_content_metadata_path)?; match layer_sboms { - Sboms::Overwrite(sboms) => write_layer_sboms(layers_dir.as_ref(), layer_name, &sboms)?, + Sboms::Overwrite(sboms) => overwrite_layer_sboms(layers_dir.as_ref(), layer_name, &sboms)?, Sboms::Keep => {} }