Skip to content

Commit e81e3ac

Browse files
committed
Convert warnings to hard errors
Signed-off-by: Natalie Klestrup Röijezon <[email protected]>
1 parent 05809f2 commit e81e3ac

File tree

2 files changed

+50
-39
lines changed

2 files changed

+50
-39
lines changed

kube-client/src/client/builder.rs

+34-39
Original file line numberDiff line numberDiff line change
@@ -91,52 +91,47 @@ impl TryFrom<Config> for ClientBuilder<GenericService> {
9191
}
9292
}
9393

94-
const PROXY_SCHEME_SOCKS5: &str = "socks5";
95-
const PROXY_SCHEME_HTTP: &str = "http";
96-
9794
match config.proxy_url.as_ref() {
98-
#[cfg(feature = "socks5")]
99-
Some(proxy_url) if proxy_url.scheme_str() == Some(PROXY_SCHEME_SOCKS5) => {
100-
let connector = hyper_socks2::SocksConnector {
101-
proxy_addr: proxy_url.clone(),
102-
auth: None,
103-
connector,
104-
};
105-
106-
make_generic_builder(connector, config)
107-
}
108-
109-
#[cfg(feature = "http-proxy")]
110-
Some(proxy_url) if proxy_url.scheme_str() == Some(PROXY_SCHEME_HTTP) => {
111-
let proxy = hyper_http_proxy::Proxy::new(hyper_http_proxy::Intercept::All, proxy_url.clone());
112-
let connector = hyper_http_proxy::ProxyConnector::from_proxy_unsecured(connector, proxy);
95+
Some(proxy_url) if proxy_url.scheme_str() == Some("socks5") => {
96+
#[cfg(feature = "socks5")]
97+
{
98+
let connector = hyper_socks2::SocksConnector {
99+
proxy_addr: proxy_url.clone(),
100+
auth: None,
101+
connector,
102+
};
103+
make_generic_builder(connector, config)
104+
}
113105

114-
make_generic_builder(connector, config)
106+
#[cfg(not(feature = "socks5"))]
107+
Err(Error::ProxyProtocolDisabled {
108+
proxy_url: proxy_url.clone(),
109+
protocol_feature: "kube/socks5",
110+
})
115111
}
116112

117-
proxy_url => {
118-
if let Some(proxy_url) = proxy_url {
119-
let missing_proxy_feature = match proxy_url.scheme_str() {
120-
Some(PROXY_SCHEME_SOCKS5) => Some("kube/socks5"),
121-
Some(PROXY_SCHEME_HTTP) => Some("kube/http-proxy"),
122-
_ => None,
123-
};
124-
if let Some(missing_proxy_feature) = missing_proxy_feature {
125-
tracing::warn!(
126-
?proxy_url,
127-
missing_proxy_feature,
128-
"proxy URL is set but kube was built without support for that protocol, ignoring..."
129-
);
130-
} else {
131-
tracing::warn!(
132-
?proxy_url,
133-
"proxy URL is set but kube does not support that protocol, ignoring..."
134-
);
135-
}
113+
Some(proxy_url) if proxy_url.scheme_str() == Some("http") => {
114+
#[cfg(feature = "http-proxy")]
115+
{
116+
let proxy =
117+
hyper_http_proxy::Proxy::new(hyper_http_proxy::Intercept::All, proxy_url.clone());
118+
let connector = hyper_http_proxy::ProxyConnector::from_proxy_unsecured(connector, proxy);
119+
120+
make_generic_builder(connector, config)
136121
}
137122

138-
make_generic_builder(connector, config)
123+
#[cfg(not(feature = "http-proxy"))]
124+
Err(Error::ProxyProtocolDisabled {
125+
proxy_url: proxy_url.clone(),
126+
protocol_feature: "kube/http-proxy",
127+
})
139128
}
129+
130+
Some(proxy_url) => Err(Error::ProxyProtocolUnsupported {
131+
proxy_url: proxy_url.clone(),
132+
}),
133+
134+
None => make_generic_builder(connector, config),
140135
}
141136
}
142137
}

kube-client/src/error.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Error handling and error types
2+
use http::Uri;
23
use thiserror::Error;
34

45
pub use kube_core::ErrorResponse;
@@ -25,6 +26,21 @@ pub enum Error {
2526
#[error("ServiceError: {0}")]
2627
Service(#[source] tower::BoxError),
2728

29+
/// Returned when the configured proxy uses an unsupported protocol.
30+
#[error("configured proxy {proxy_url:?} uses an unsupported protocol")]
31+
ProxyProtocolUnsupported {
32+
/// The URL of the proxy.
33+
proxy_url: Uri,
34+
},
35+
/// Returned when the configured proxy uses a protocol that requires a Cargo feature that is currently disabled
36+
#[error("configured proxy {proxy_url:?} requires the disabled feature {protocol_feature:?}")]
37+
ProxyProtocolDisabled {
38+
/// The URL of the proxy.
39+
proxy_url: Uri,
40+
/// The Cargo feature that the proxy protocol requires.
41+
protocol_feature: &'static str,
42+
},
43+
2844
/// UTF-8 Error
2945
#[error("UTF-8 Error: {0}")]
3046
FromUtf8(#[source] std::string::FromUtf8Error),

0 commit comments

Comments
 (0)