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