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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
use http::header::InvalidHeaderValue;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("ApiError: {0} ({0:?})")]
Api(#[source] ErrorResponse),
#[error("ReqwestError: {0}")]
ReqwestError(#[from] reqwest::Error),
#[error("HttpError: {0}")]
HttpError(#[from] http::Error),
#[error("InternalUrlError: {0}")]
InternalUrlError(#[from] url::ParseError),
#[error("Error deserializing response")]
SerdeError(#[from] serde_json::Error),
#[error("Error building request")]
RequestBuild,
#[error("Error executing request")]
RequestSend,
#[error("Error parsing response")]
RequestParse,
#[error("Invalid API method {0}")]
InvalidMethod(String),
#[error("Request validation failed with {0}")]
RequestValidation(String),
#[error("Dynamic resource conversion failed {0}")]
DynamicResource(String),
#[error("Error loading kubeconfig: {0}")]
Kubeconfig(#[from] ConfigError),
#[error("SslError: {0}")]
SslError(String),
#[cfg(feature = "native-tls")]
#[error("OpensslError: {0}")]
OpensslError(#[from] openssl::error::ErrorStack),
}
#[derive(Error, Debug)]
#[allow(missing_docs)]
pub enum ConfigError {
#[error("Invalid basic auth: {0}")]
InvalidBasicAuth(#[source] InvalidHeaderValue),
#[error("Invalid bearer token: {0}")]
InvalidBearerToken(#[source] InvalidHeaderValue),
#[error("Tried to refresh a token and got a non-refreshable token response")]
UnrefreshableTokenResponse,
#[error("Failed to infer config.. cluster env: ({cluster_env}), kubeconfig: ({kubeconfig})")]
ConfigInferenceExhausted {
cluster_env: Box<Error>,
#[source]
kubeconfig: Box<Error>,
},
#[error("Unable to load in cluster config, {hostenv} and {portenv} must be defined")]
MissingInClusterVariables {
hostenv: &'static str,
portenv: &'static str,
},
#[error("Unable to load incluster default namespace: {0}")]
InvalidInClusterNamespace(#[source] Box<Error>),
#[error("Unable to load in cluster token: {0}")]
InvalidInClusterToken(#[source] Box<Error>),
#[error("Malformed url: {0}")]
MalformedUrl(#[from] url::ParseError),
#[error("exec-plugin response did not contain a status")]
ExecPluginFailed,
#[error("Malformed token expiration date: {0}")]
MalformedTokenExpirationDate(#[source] chrono::ParseError),
#[error("Missing GOOGLE_APPLICATION_CREDENTIALS env")]
MissingGoogleCredentials,
#[error("Unable to load OAuth2 credentials file: {0}")]
OAuth2LoadCredentials(#[source] std::io::Error),
#[error("Unable to parse OAuth2 credentials file: {0}")]
OAuth2ParseCredentials(#[source] serde_json::Error),
#[error("Unable to request token: {0}")]
OAuth2RequestToken(#[source] reqwest::Error),
#[error("Fail to retrieve new credential {0:?}")]
OAuth2RetrieveCredentials(Box<reqwest::Response>),
#[error("Unable to parse token: {0}")]
OAuth2ParseToken(#[source] reqwest::Error),
#[error("Unable to load config file: {0}")]
LoadConfigFile(#[source] Box<Error>),
#[error("Unable to load current context: {context_name}")]
LoadContext { context_name: String },
#[error("Unable to load cluster of context: {cluster_name}")]
LoadClusterOfContext { cluster_name: String },
#[error("Unable to find named user: {user_name}")]
FindUser { user_name: String },
#[error("Unable to find path of kubeconfig")]
NoKubeconfigPath,
#[error("Failed to decode base64: {0}")]
Base64Decode(#[source] base64::DecodeError),
#[error("Failed to compute the absolute path of '{path:?}'")]
NoAbsolutePath { path: PathBuf },
#[error("Failed to read '{path:?}': {source}")]
ReadFile {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("Failed to get data/file with base64 format")]
NoBase64FileOrData,
#[error("Failed to get data/file")]
NoFileOrData,
#[error("Failed to load certificate: {0}")]
LoadCert(#[source] reqwest::Error),
#[error("Failed to parse Kubeconfig YAML: {0}")]
ParseYaml(#[source] serde_yaml::Error),
#[error("Unable to run auth exec: {0}")]
AuthExecStart(#[source] std::io::Error),
#[error("Auth exec command '{cmd}' failed with status {status}: {out:?}")]
AuthExecRun {
cmd: String,
status: std::process::ExitStatus,
out: std::process::Output,
},
#[error("Failed to parse auth exec output: {0}")]
AuthExecParse(#[source] serde_json::Error),
}
#[derive(Error, Deserialize, Serialize, Debug, Clone, Eq, PartialEq)]
#[error("{message}: {reason}")]
pub struct ErrorResponse {
pub status: String,
#[serde(default)]
pub message: String,
#[serde(default)]
pub reason: String,
pub code: u16,
}