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 Machines,
13 Local,
14 Test,
15}
16
17impl Platform {
18 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 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}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash)]
67#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
68#[serde(rename_all = "lowercase")]
69pub enum BindingsMode {
70 Direct,
72 Grpc,
74}
75
76impl BindingsMode {
77 pub fn as_str(&self) -> &'static str {
79 match self {
80 BindingsMode::Direct => "direct",
81 BindingsMode::Grpc => "grpc",
82 }
83 }
84}
85
86impl std::fmt::Display for BindingsMode {
87 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
88 write!(f, "{}", self.as_str())
89 }
90}
91
92impl std::str::FromStr for BindingsMode {
93 type Err = String;
94
95 fn from_str(s: &str) -> Result<Self, Self::Err> {
96 match s.to_lowercase().as_str() {
97 "direct" => Ok(BindingsMode::Direct),
98 "grpc" => Ok(BindingsMode::Grpc),
99 _ => Err(format!(
100 "Invalid bindings mode: '{}'. Must be 'direct' or 'grpc'",
101 s
102 )),
103 }
104 }
105}
106
107impl Default for BindingsMode {
108 fn default() -> Self {
109 BindingsMode::Direct
110 }
111}