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#[serde(rename_all = "camelCase", deny_unknown_fields)]
7pub enum Platform {
8    Aws,
9    Gcp,
10    Azure,
11    Kubernetes,
12    Machines,
13    Local,
14    Test,
15}
16
17impl Platform {
18    /// All deployable platforms (excludes Test).
19    pub const DEPLOYABLE: &[Platform] = &[
20        Platform::Aws,
21        Platform::Gcp,
22        Platform::Azure,
23        Platform::Kubernetes,
24        Platform::Machines,
25        Platform::Local,
26    ];
27
28    /// Returns the string representation of the platform.
29    pub fn as_str(&self) -> &'static str {
30        match self {
31            Platform::Aws => "aws",
32            Platform::Gcp => "gcp",
33            Platform::Azure => "azure",
34            Platform::Kubernetes => "kubernetes",
35            Platform::Machines => "machines",
36            Platform::Local => "local",
37            Platform::Test => "test",
38        }
39    }
40}
41
42impl std::fmt::Display for Platform {
43    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44        write!(f, "{}", self.as_str())
45    }
46}
47
48impl std::str::FromStr for Platform {
49    type Err = String;
50
51    fn from_str(s: &str) -> Result<Self, Self::Err> {
52        match s.to_lowercase().as_str() {
53            "aws" => Ok(Platform::Aws),
54            "gcp" => Ok(Platform::Gcp),
55            "azure" => Ok(Platform::Azure),
56            "kubernetes" => Ok(Platform::Kubernetes),
57            "machines" => Ok(Platform::Machines),
58            "local" => Ok(Platform::Local),
59            "test" => Ok(Platform::Test),
60            _ => Err(format!("'{}' is not a valid platform", s)),
61        }
62    }
63}