1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
use std::str;
use thiserror::Error;
use super::*;
impl Cluster {
pub fn all_locations(&self) -> Vec<Location> {
let aws = self.locations.aws.iter().map(|aws| aws.region.into());
let azure = self.locations.azure.iter().map(|azure| azure.region.into());
aws.chain(azure).collect()
}
}
impl fmt::Display for Cluster {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Cluster").field("name", &self.name).finish()
}
}
impl From<String> for ClusterName {
fn from(name: String) -> Self {
Self(name)
}
}
impl From<&str> for ClusterName {
fn from(text: &str) -> Self {
text.to_string().into()
}
}
impl fmt::Display for ClusterName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl str::FromStr for ClusterName {
type Err = Infallible;
fn from_str(text: &str) -> Result<Self, Self::Err> {
Ok(text.into())
}
}
impl AsRef<str> for ClusterName {
fn as_ref(&self) -> &str {
self.0.as_ref()
}
}
impl ops::Deref for ClusterName {
type Target = str;
fn deref(&self) -> &Self::Target {
self.0.deref()
}
}
impl PartialEq<&str> for ClusterName {
fn eq(&self, other: &&str) -> bool {
self.0.eq(other)
}
}
impl PartialEq<String> for ClusterName {
fn eq(&self, other: &String) -> bool {
self.0.eq(other)
}
}
impl From<AwsRegion> for ClusterLocationAws {
fn from(region: AwsRegion) -> Self {
Self {
region,
account_principal: None,
}
}
}
impl From<AzureRegion> for ClusterLocationAzure {
fn from(region: AzureRegion) -> Self {
Self { region }
}
}
impl From<&[Location]> for ClusterLocations {
fn from(locations: &[Location]) -> Self {
let mut aws = vec![];
let mut azure = vec![];
for location in locations {
match location {
Location::Aws(region) => aws.push((*region).into()),
Location::Azure(region) => azure.push((*region).into()),
}
}
Self { aws, azure }
}
}
impl Provider {
pub(crate) fn as_str(&self) -> &'static str {
match self {
Self::Eks => "eks",
Self::Aks => "aks",
Self::Kops => "kops",
Self::Generic => "generic",
}
}
}
impl fmt::Display for Provider {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let text = self.as_str();
if f.alternate() {
text.to_uppercase().fmt(f)
} else {
text.fmt(f)
}
}
}
#[derive(Debug, Error)]
#[error(r#"Invalid K8s provider "{provider}"#)]
pub struct InvalidProvider {
pub provider: String,
}
impl InvalidProvider {
pub(crate) fn new(provider: &str) -> Self {
let provider = provider.to_string();
Self { provider }
}
}
impl str::FromStr for Provider {
type Err = InvalidProvider;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"eks" => Ok(Self::Eks),
"aks" => Ok(Self::Aks),
"kops" => Ok(Self::Kops),
"genetic" => Ok(Self::Generic),
other => Err(InvalidProvider::new(other)),
}
}
}