Skip to main content

kea_lifecycle/cmd/launcher/
metadata.rs

1use super::error::{LauncherError, Result};
2use crate::buildpack::Version;
3use serde::{Deserialize, Serialize};
4use std::ops::Not;
5use std::path::{Path, PathBuf};
6
7#[derive(Debug, Serialize, Deserialize)]
8#[serde(rename = "kebab-case")]
9pub struct Metadata {
10    pub buildpack_default_process_type: Option<String>,
11    pub processes: Vec<Process>,
12    pub buildpacks: Vec<Buildpack>,
13}
14
15impl Metadata {
16    pub fn from_file(path: impl AsRef<Path>) -> Result<Self> {
17        let toml_str = std::fs::read_to_string(path).map_err(LauncherError::ReadingMetadata)?;
18        toml::from_str(&toml_str).map_err(LauncherError::ParsingMetadata)
19    }
20    pub fn from_layers_dir(layers_dir: impl AsRef<Path>) -> Result<Self> {
21        Self::from_file(layers_dir.as_ref().join("config").join("metadata.toml"))
22    }
23}
24
25#[derive(Debug, Clone, Default, Serialize, Deserialize)]
26pub struct Process {
27    #[serde(rename = "type")]
28    pub proc_type: String,
29
30    pub command: RawCommand,
31    pub args: Vec<String>,
32    pub direct: bool,
33    #[serde(skip_serializing_if = "<&bool>::not")]
34    pub default: bool,
35    pub buildpack_id: String,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub working_dir: Option<PathBuf>,
38    pub platform_api: Option<Version>,
39}
40
41#[derive(Debug, Clone, Default, Serialize, Deserialize)]
42pub struct RawCommand {
43    pub entries: Vec<String>,
44    pub platform_api: Version,
45}
46
47#[derive(Debug, Serialize, Deserialize)]
48pub struct Buildpack {
49    pub api: Version,
50    pub id: Version,
51}