shrub_rs/models/
params.rs

1use core::fmt;
2use serde::{Deserialize, Serialize};
3use std::{
4    collections::HashMap,
5    fmt::{Display, Formatter},
6};
7
8/// AWS S3 Location description.
9#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
10pub struct S3Location {
11    /// S3 bucket.
12    pub bucket: String,
13    /// Path within S3 bucket.
14    pub path: String,
15}
16
17/// Description of how to copy an AWS S3 file.
18#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
19pub struct S3CopyFile {
20    /// Location of S3 file to copy.
21    pub source: S3Location,
22
23    /// S3 destination to put copy.
24    pub destination: S3Location,
25
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub display_name: Option<String>,
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub build_variants: Option<Vec<String>>,
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub optional: Option<bool>,
32}
33
34/// Key-Value pair used to create a parameter map.
35#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
36pub struct KeyValueParam {
37    /// Key of Key-Value pair.
38    pub key: String,
39    /// Value of Key-Value pair.
40    pub value: String,
41}
42
43#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
44#[serde(untagged)]
45pub enum ParamValue {
46    Bool(bool),
47    String(String),
48    Number(u64),
49    Float(f64),
50    List(Vec<String>),
51    Map(HashMap<String, String>),
52    KeyValueList(Vec<KeyValueParam>),
53    S3CopyList(Vec<S3CopyFile>),
54}
55
56impl Display for ParamValue {
57    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
58        use ParamValue::*;
59        match self {
60            Bool(b) => write!(f, "{}", b),
61            String(s) => write!(f, "{}", s),
62            Number(n) => write!(f, "{}", n),
63            Float(d) => write!(f, "{}", d),
64            List(l) => write!(f, "{}", l.join(", ")),
65            Map(_) => write!(f, "map"),
66            KeyValueList(_) => write!(f, "kvs"),
67            S3CopyList(_) => write!(f, "s3"),
68        }
69    }
70}
71
72impl From<bool> for ParamValue {
73    fn from(item: bool) -> ParamValue {
74        ParamValue::Bool(item)
75    }
76}
77
78impl From<&str> for ParamValue {
79    fn from(item: &str) -> ParamValue {
80        ParamValue::String(item.to_string())
81    }
82}
83
84impl From<u64> for ParamValue {
85    fn from(item: u64) -> ParamValue {
86        ParamValue::Number(item)
87    }
88}
89
90impl From<f64> for ParamValue {
91    fn from(item: f64) -> ParamValue {
92        ParamValue::Float(item)
93    }
94}