1use serde::{Deserialize, Serialize};
2
3#[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 pub const DEPLOYABLE: &[Platform] = &[
19 Platform::Aws,
20 Platform::Gcp,
21 Platform::Azure,
22 Platform::Kubernetes,
23 Platform::Local,
24 ];
25
26 pub const STABLE: &[Platform] = &[Platform::Aws, Platform::Gcp, Platform::Azure];
28
29 pub fn is_experimental(&self) -> bool {
31 matches!(self, Platform::Kubernetes | Platform::Local)
32 }
33
34 pub fn as_str(&self) -> &'static str {
36 match self {
37 Platform::Aws => "aws",
38 Platform::Gcp => "gcp",
39 Platform::Azure => "azure",
40 Platform::Kubernetes => "kubernetes",
41 Platform::Local => "local",
42 Platform::Test => "test",
43 }
44 }
45}
46
47impl std::fmt::Display for Platform {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 write!(f, "{}", self.as_str())
50 }
51}
52
53impl std::str::FromStr for Platform {
54 type Err = String;
55
56 fn from_str(s: &str) -> Result<Self, Self::Err> {
57 match s.to_lowercase().as_str() {
58 "aws" => Ok(Platform::Aws),
59 "gcp" => Ok(Platform::Gcp),
60 "azure" => Ok(Platform::Azure),
61 "kubernetes" => Ok(Platform::Kubernetes),
62 "local" => Ok(Platform::Local),
63 "test" => Ok(Platform::Test),
64 _ => Err(format!("'{}' is not a valid platform", s)),
65 }
66 }
67}
68
69#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash)]
71#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
72#[serde(rename_all = "lowercase")]
73pub enum BindingsMode {
74 Direct,
76 Grpc,
78}
79
80impl BindingsMode {
81 pub fn as_str(&self) -> &'static str {
83 match self {
84 BindingsMode::Direct => "direct",
85 BindingsMode::Grpc => "grpc",
86 }
87 }
88}
89
90impl std::fmt::Display for BindingsMode {
91 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
92 write!(f, "{}", self.as_str())
93 }
94}
95
96impl std::str::FromStr for BindingsMode {
97 type Err = String;
98
99 fn from_str(s: &str) -> Result<Self, Self::Err> {
100 match s.to_lowercase().as_str() {
101 "direct" => Ok(BindingsMode::Direct),
102 "grpc" => Ok(BindingsMode::Grpc),
103 _ => Err(format!(
104 "Invalid bindings mode: '{}'. Must be 'direct' or 'grpc'",
105 s
106 )),
107 }
108 }
109}
110
111impl Default for BindingsMode {
112 fn default() -> Self {
113 BindingsMode::Direct
114 }
115}