Skip to content

Commit

Permalink
Convert warnings to hard errors
Browse files Browse the repository at this point in the history
Signed-off-by: Natalie Klestrup Röijezon <[email protected]>
  • Loading branch information
nightkr committed Nov 7, 2024
1 parent 05809f2 commit e81e3ac
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 39 deletions.
73 changes: 34 additions & 39 deletions kube-client/src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,52 +91,47 @@ impl TryFrom<Config> for ClientBuilder<GenericService> {
}
}

const PROXY_SCHEME_SOCKS5: &str = "socks5";
const PROXY_SCHEME_HTTP: &str = "http";

match config.proxy_url.as_ref() {
#[cfg(feature = "socks5")]
Some(proxy_url) if proxy_url.scheme_str() == Some(PROXY_SCHEME_SOCKS5) => {
let connector = hyper_socks2::SocksConnector {
proxy_addr: proxy_url.clone(),
auth: None,
connector,
};

make_generic_builder(connector, config)
}

#[cfg(feature = "http-proxy")]
Some(proxy_url) if proxy_url.scheme_str() == Some(PROXY_SCHEME_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);
Some(proxy_url) if proxy_url.scheme_str() == Some("socks5") => {
#[cfg(feature = "socks5")]
{
let connector = hyper_socks2::SocksConnector {
proxy_addr: proxy_url.clone(),

Check warning on line 99 in kube-client/src/client/builder.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/builder.rs#L99

Added line #L99 was not covered by tests
auth: None,
connector,
};
make_generic_builder(connector, config)

Check warning on line 103 in kube-client/src/client/builder.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/builder.rs#L103

Added line #L103 was not covered by tests
}

make_generic_builder(connector, config)
#[cfg(not(feature = "socks5"))]
Err(Error::ProxyProtocolDisabled {
proxy_url: proxy_url.clone(),
protocol_feature: "kube/socks5",
})
}

proxy_url => {
if let Some(proxy_url) = proxy_url {
let missing_proxy_feature = match proxy_url.scheme_str() {
Some(PROXY_SCHEME_SOCKS5) => Some("kube/socks5"),
Some(PROXY_SCHEME_HTTP) => Some("kube/http-proxy"),
_ => None,
};
if let Some(missing_proxy_feature) = missing_proxy_feature {
tracing::warn!(
?proxy_url,
missing_proxy_feature,
"proxy URL is set but kube was built without support for that protocol, ignoring..."
);
} else {
tracing::warn!(
?proxy_url,
"proxy URL is set but kube does not support that protocol, ignoring..."
);
}
Some(proxy_url) if proxy_url.scheme_str() == Some("http") => {
#[cfg(feature = "http-proxy")]
{
let proxy =

Check warning on line 116 in kube-client/src/client/builder.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/builder.rs#L116

Added line #L116 was not covered by tests
hyper_http_proxy::Proxy::new(hyper_http_proxy::Intercept::All, proxy_url.clone());
let connector = hyper_http_proxy::ProxyConnector::from_proxy_unsecured(connector, proxy);

Check warning on line 118 in kube-client/src/client/builder.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/builder.rs#L118

Added line #L118 was not covered by tests

make_generic_builder(connector, config)

Check warning on line 120 in kube-client/src/client/builder.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/builder.rs#L120

Added line #L120 was not covered by tests
}

make_generic_builder(connector, config)
#[cfg(not(feature = "http-proxy"))]
Err(Error::ProxyProtocolDisabled {
proxy_url: proxy_url.clone(),

Check warning on line 125 in kube-client/src/client/builder.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/builder.rs#L124-L125

Added lines #L124 - L125 were not covered by tests
protocol_feature: "kube/http-proxy",
})
}

Some(proxy_url) => Err(Error::ProxyProtocolUnsupported {
proxy_url: proxy_url.clone(),

Check warning on line 131 in kube-client/src/client/builder.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/builder.rs#L130-L131

Added lines #L130 - L131 were not covered by tests
}),

None => make_generic_builder(connector, config),
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions kube-client/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Error handling and error types
use http::Uri;
use thiserror::Error;

pub use kube_core::ErrorResponse;
Expand All @@ -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),
Expand Down

0 comments on commit e81e3ac

Please sign in to comment.