Skip to main content

alien_core/
platform.rs

1use serde::{Deserialize, Serialize};
2
3/// Represents the target cloud platform.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash)]
5#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
6#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
7#[serde(rename_all = "camelCase", deny_unknown_fields)]
8pub enum Platform {
9    Aws,
10    Gcp,
11    Azure,
12    Kubernetes,
13    Machines,
14    Local,
15    /// Test-only platform; not offered to stack authors.
16    #[cfg_attr(feature = "jsonschema", schemars(skip))]
17    Test,
18}
19
20impl Platform {
21    /// All deployable platforms (excludes Test).
22    pub const DEPLOYABLE: &[Platform] = &[
23        Platform::Aws,
24        Platform::Gcp,
25        Platform::Azure,
26        Platform::Kubernetes,
27        Platform::Machines,
28        Platform::Local,
29    ];
30
31    /// Returns the string representation of the platform.
32    pub fn as_str(&self) -> &'static str {
33        match self {
34            Platform::Aws => "aws",
35            Platform::Gcp => "gcp",
36            Platform::Azure => "azure",
37            Platform::Kubernetes => "kubernetes",
38            Platform::Machines => "machines",
39            Platform::Local => "local",
40            Platform::Test => "test",
41        }
42    }
43}
44
45impl std::fmt::Display for Platform {
46    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47        write!(f, "{}", self.as_str())
48    }
49}
50
51impl std::str::FromStr for Platform {
52    type Err = String;
53
54    fn from_str(s: &str) -> Result<Self, Self::Err> {
55        match s.to_lowercase().as_str() {
56            "aws" => Ok(Platform::Aws),
57            "gcp" => Ok(Platform::Gcp),
58            "azure" => Ok(Platform::Azure),
59            "kubernetes" => Ok(Platform::Kubernetes),
60            "machines" => Ok(Platform::Machines),
61            "local" => Ok(Platform::Local),
62            "test" => Ok(Platform::Test),
63            _ => Err(format!("'{}' is not a valid platform", s)),
64        }
65    }
66}