use std::fmt;
use std::str::FromStr;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CloudProvider {
Local,
Docker,
MzCompose,
Cloudtest,
Aws,
Gcp,
Azure,
Generic,
}
impl CloudProvider {
pub fn is_cloud(&self) -> bool {
matches!(self, Self::Aws | Self::Gcp | Self::Azure | Self::Generic)
}
}
impl fmt::Display for CloudProvider {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CloudProvider::Local => f.write_str("local"),
CloudProvider::Docker => f.write_str("docker"),
CloudProvider::MzCompose => f.write_str("mzcompose"),
CloudProvider::Cloudtest => f.write_str("cloudtest"),
CloudProvider::Aws => f.write_str("aws"),
CloudProvider::Gcp => f.write_str("gcp"),
CloudProvider::Azure => f.write_str("azure"),
CloudProvider::Generic => f.write_str("generic"),
}
}
}
impl FromStr for CloudProvider {
type Err = InvalidCloudProviderError;
fn from_str(s: &str) -> Result<CloudProvider, InvalidCloudProviderError> {
match s.to_lowercase().as_ref() {
"local" => Ok(CloudProvider::Local),
"docker" => Ok(CloudProvider::Docker),
"mzcompose" => Ok(CloudProvider::MzCompose),
"cloudtest" => Ok(CloudProvider::Cloudtest),
"aws" => Ok(CloudProvider::Aws),
"gcp" => Ok(CloudProvider::Gcp),
"azure" => Ok(CloudProvider::Azure),
"generic" => Ok(CloudProvider::Generic),
_ => Err(InvalidCloudProviderError),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct InvalidCloudProviderError;
impl fmt::Display for InvalidCloudProviderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("invalid cloud provider")
}
}
impl std::error::Error for InvalidCloudProviderError {}