1use std::fmt;
11use std::str::FromStr;
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15pub enum CloudProvider {
16 Local,
18 Docker,
20 MzCompose,
23 Cloudtest,
25 Aws,
27 Gcp,
29 Azure,
31 Generic,
33}
34
35impl CloudProvider {
36 pub fn is_cloud(&self) -> bool {
38 matches!(self, Self::Aws | Self::Gcp | Self::Azure | Self::Generic)
39 }
40}
41
42impl fmt::Display for CloudProvider {
43 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44 match self {
45 CloudProvider::Local => f.write_str("local"),
46 CloudProvider::Docker => f.write_str("docker"),
47 CloudProvider::MzCompose => f.write_str("mzcompose"),
48 CloudProvider::Cloudtest => f.write_str("cloudtest"),
49 CloudProvider::Aws => f.write_str("aws"),
50 CloudProvider::Gcp => f.write_str("gcp"),
51 CloudProvider::Azure => f.write_str("azure"),
52 CloudProvider::Generic => f.write_str("generic"),
53 }
54 }
55}
56
57impl FromStr for CloudProvider {
58 type Err = InvalidCloudProviderError;
59
60 fn from_str(s: &str) -> Result<CloudProvider, InvalidCloudProviderError> {
61 match s.to_lowercase().as_ref() {
62 "local" => Ok(CloudProvider::Local),
63 "docker" => Ok(CloudProvider::Docker),
64 "mzcompose" => Ok(CloudProvider::MzCompose),
65 "cloudtest" => Ok(CloudProvider::Cloudtest),
66 "aws" => Ok(CloudProvider::Aws),
67 "gcp" => Ok(CloudProvider::Gcp),
68 "azure" => Ok(CloudProvider::Azure),
69 "generic" => Ok(CloudProvider::Generic),
70 _ => Err(InvalidCloudProviderError),
71 }
72 }
73}
74
75#[derive(Debug, Clone, PartialEq)]
77pub struct InvalidCloudProviderError;
78
79impl fmt::Display for InvalidCloudProviderError {
80 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
81 f.write_str("invalid cloud provider")
82 }
83}
84
85impl std::error::Error for InvalidCloudProviderError {}