kea-lifecycle 0.1.0

buildpack lifecycle
Documentation
use super::error::{LauncherError, Result};
use crate::buildpack::Version;
use serde::{Deserialize, Serialize};
use std::ops::Not;
use std::path::{Path, PathBuf};

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename = "kebab-case")]
pub struct Metadata {
    pub buildpack_default_process_type: Option<String>,
    pub processes: Vec<Process>,
    pub buildpacks: Vec<Buildpack>,
}

impl Metadata {
    pub fn from_file(path: impl AsRef<Path>) -> Result<Self> {
        let toml_str = std::fs::read_to_string(path).map_err(LauncherError::ReadingMetadata)?;
        toml::from_str(&toml_str).map_err(LauncherError::ParsingMetadata)
    }
    pub fn from_layers_dir(layers_dir: impl AsRef<Path>) -> Result<Self> {
        Self::from_file(layers_dir.as_ref().join("config").join("metadata.toml"))
    }
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Process {
    #[serde(rename = "type")]
    pub proc_type: String,

    pub command: RawCommand,
    pub args: Vec<String>,
    pub direct: bool,
    #[serde(skip_serializing_if = "<&bool>::not")]
    pub default: bool,
    pub buildpack_id: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub working_dir: Option<PathBuf>,
    pub platform_api: Option<Version>,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct RawCommand {
    pub entries: Vec<String>,
    pub platform_api: Version,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Buildpack {
    pub api: Version,
    pub id: Version,
}