1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
910use std::fmt;
11use std::str::FromStr;
1213/// Identifies a supported cloud provider.
14#[derive(Debug, Clone, PartialEq, Eq)]
15pub enum CloudProvider {
16/// A pseudo-provider value used by local development environments.
17Local,
18/// A pseudo-provider value used by Docker.
19Docker,
20/// A deprecated psuedo-provider value used by mzcompose.
21// TODO(benesch): remove once v0.39 ships.
22MzCompose,
23/// A pseudo-provider value used by cloudtest.
24Cloudtest,
25/// Amazon Web Services.
26Aws,
27/// Google Cloud Platform
28Gcp,
29/// Microsoft Azure
30Azure,
31/// Other generic cloud provider
32Generic,
33}
3435impl CloudProvider {
36/// Returns true if this provider actually runs in the cloud
37pub fn is_cloud(&self) -> bool {
38matches!(self, Self::Aws | Self::Gcp | Self::Azure | Self::Generic)
39 }
40}
4142impl fmt::Display for CloudProvider {
43fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44match 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}
5657impl FromStr for CloudProvider {
58type Err = InvalidCloudProviderError;
5960fn from_str(s: &str) -> Result<CloudProvider, InvalidCloudProviderError> {
61match 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}
7475/// The error type for [`CloudProvider::from_str`].
76#[derive(Debug, Clone, PartialEq)]
77pub struct InvalidCloudProviderError;
7879impl fmt::Display for InvalidCloudProviderError {
80fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
81 f.write_str("invalid cloud provider")
82 }
83}
8485impl std::error::Error for InvalidCloudProviderError {}