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    Local,
13    Test,
14}
15
16impl Platform {
17    /// All deployable platforms (excludes Test).
18    pub const DEPLOYABLE: &[Platform] = &[
19        Platform::Aws,
20        Platform::Gcp,
21        Platform::Azure,
22        Platform::Kubernetes,
23        Platform::Local,
24    ];
25
26    /// Returns the string representation of the platform.
27    pub fn as_str(&self) -> &'static str {
28        match self {
29            Platform::Aws => "aws",
30            Platform::Gcp => "gcp",
31            Platform::Azure => "azure",
32            Platform::Kubernetes => "kubernetes",
33            Platform::Local => "local",
34            Platform::Test => "test",
35        }
36    }
37}
38
39impl std::fmt::Display for Platform {
40    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41        write!(f, "{}", self.as_str())
42    }
43}
44
45impl std::str::FromStr for Platform {
46    type Err = String;
47
48    fn from_str(s: &str) -> Result<Self, Self::Err> {
49        match s.to_lowercase().as_str() {
50            "aws" => Ok(Platform::Aws),
51            "gcp" => Ok(Platform::Gcp),
52            "azure" => Ok(Platform::Azure),
53            "kubernetes" => Ok(Platform::Kubernetes),
54            "local" => Ok(Platform::Local),
55            "test" => Ok(Platform::Test),
56            _ => Err(format!("'{}' is not a valid platform", s)),
57        }
58    }
59}
60
61/// How bindings are delivered to the application
62#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash)]
63#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
64#[serde(rename_all = "lowercase")]
65pub enum BindingsMode {
66    /// Load bindings directly from environment variables (standalone processes)
67    Direct,
68    /// Load bindings via gRPC from alien-runtime
69    Grpc,
70}
71
72impl BindingsMode {
73    /// Returns the string representation of the bindings mode.
74    pub fn as_str(&self) -> &'static str {
75        match self {
76            BindingsMode::Direct => "direct",
77            BindingsMode::Grpc => "grpc",
78        }
79    }
80}
81
82impl std::fmt::Display for BindingsMode {
83    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
84        write!(f, "{}", self.as_str())
85    }
86}
87
88impl std::str::FromStr for BindingsMode {
89    type Err = String;
90
91    fn from_str(s: &str) -> Result<Self, Self::Err> {
92        match s.to_lowercase().as_str() {
93            "direct" => Ok(BindingsMode::Direct),
94            "grpc" => Ok(BindingsMode::Grpc),
95            _ => Err(format!(
96                "Invalid bindings mode: '{}'. Must be 'direct' or 'grpc'",
97                s
98            )),
99        }
100    }
101}
102
103impl Default for BindingsMode {
104    fn default() -> Self {
105        BindingsMode::Direct
106    }
107}