diff --git a/kube-client/src/client/builder.rs b/kube-client/src/client/builder.rs index 05edf80b4..05ff85343 100644 --- a/kube-client/src/client/builder.rs +++ b/kube-client/src/client/builder.rs @@ -92,26 +92,46 @@ impl TryFrom for ClientBuilder { } match config.proxy_url.as_ref() { - #[cfg(feature = "socks5")] Some(proxy_url) if proxy_url.scheme_str() == Some("socks5") => { - let connector = hyper_socks2::SocksConnector { - proxy_addr: proxy_url.clone(), - auth: None, - connector, - }; - - make_generic_builder(connector, config) + #[cfg(feature = "socks5")] + { + let connector = hyper_socks2::SocksConnector { + proxy_addr: proxy_url.clone(), + auth: None, + connector, + }; + make_generic_builder(connector, config) + } + + #[cfg(not(feature = "socks5"))] + Err(Error::ProxyProtocolDisabled { + proxy_url: proxy_url.clone(), + protocol_feature: "kube/socks5", + }) } - #[cfg(feature = "http-proxy")] Some(proxy_url) if proxy_url.scheme_str() == Some("http") => { - let proxy = hyper_http_proxy::Proxy::new(hyper_http_proxy::Intercept::All, proxy_url.clone()); - let connector = hyper_http_proxy::ProxyConnector::from_proxy_unsecured(connector, proxy); - - make_generic_builder(connector, config) + #[cfg(feature = "http-proxy")] + { + let proxy = + hyper_http_proxy::Proxy::new(hyper_http_proxy::Intercept::All, proxy_url.clone()); + let connector = hyper_http_proxy::ProxyConnector::from_proxy_unsecured(connector, proxy); + + make_generic_builder(connector, config) + } + + #[cfg(not(feature = "http-proxy"))] + Err(Error::ProxyProtocolDisabled { + proxy_url: proxy_url.clone(), + protocol_feature: "kube/http-proxy", + }) } - _ => make_generic_builder(connector, config), + Some(proxy_url) => Err(Error::ProxyProtocolUnsupported { + proxy_url: proxy_url.clone(), + }), + + None => make_generic_builder(connector, config), } } } diff --git a/kube-client/src/error.rs b/kube-client/src/error.rs index 23bd2a6a9..28296c6c5 100644 --- a/kube-client/src/error.rs +++ b/kube-client/src/error.rs @@ -1,4 +1,5 @@ //! Error handling and error types +use http::Uri; use thiserror::Error; pub use kube_core::ErrorResponse; @@ -25,6 +26,21 @@ pub enum Error { #[error("ServiceError: {0}")] Service(#[source] tower::BoxError), + /// Returned when the configured proxy uses an unsupported protocol. + #[error("configured proxy {proxy_url:?} uses an unsupported protocol")] + ProxyProtocolUnsupported { + /// The URL of the proxy. + proxy_url: Uri, + }, + /// Returned when the configured proxy uses a protocol that requires a Cargo feature that is currently disabled + #[error("configured proxy {proxy_url:?} requires the disabled feature {protocol_feature:?}")] + ProxyProtocolDisabled { + /// The URL of the proxy. + proxy_url: Uri, + /// The Cargo feature that the proxy protocol requires. + protocol_feature: &'static str, + }, + /// UTF-8 Error #[error("UTF-8 Error: {0}")] FromUtf8(#[source] std::string::FromUtf8Error),