use super::error::{LauncherError, Result};
use super::metadata::{Buildpack, Metadata};
use crate::buildpack::args::DepreciationMode;
use crate::buildpack::{APIs, Version};
pub fn verify_buildpack_apis(md: &Metadata, apis: &APIs, dep_mode: DepreciationMode) -> Result<()> {
for bp in &md.buildpacks {
verify_buiildpack_api(bp, apis, dep_mode)?;
}
Ok(())
}
pub fn verify_buiildpack_api(
bp: &Buildpack,
apis: &APIs,
dep_mode: DepreciationMode,
) -> Result<()> {
if !apis.is_supported(bp.api) {
return Err(LauncherError::UnsupportedBuildpackApi(bp.api));
}
if apis.is_depreciated(bp.api) {
match dep_mode {
DepreciationMode::Quiet => {}
DepreciationMode::Warn => {
log::warn!(
"Depreciated buildpack api ({:?}) has been requested.",
bp.api
)
}
DepreciationMode::Error => {
log::error!("Depreciated buildpack api requested ({:?}", bp.api);
log::error!("Depreciated apis are disabled.");
return Err(LauncherError::DepreciatedBuildpackApi(bp.api));
}
}
}
Ok(())
}
pub fn verify_platform_api(
platform_version: Version,
apis: &APIs,
dep_mode: DepreciationMode,
) -> Result<()> {
if !apis.is_supported(platform_version) {
return Err(LauncherError::UnsupportedPlatformApi(platform_version));
}
if apis.is_depreciated(platform_version) {
match dep_mode {
DepreciationMode::Quiet => {}
DepreciationMode::Warn => {
log::warn!(
"Depreciated platform api ({:?}) has been requested.",
platform_version
)
}
DepreciationMode::Error => {
log::error!("Depreciated platform api requested ({:?}", platform_version);
log::error!("Depreciated apis are disabled.");
return Err(LauncherError::DepreciatedBuildpackApi(platform_version));
}
}
}
Ok(())
}