Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make rustls-tls an optional feature for reqwest. #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ base64 = "0.13.0"
consulrs_derive = { version = "0.1.0", path = "consulrs_derive" }
derive_builder = "0.10.2"
http = "0.2.5"
reqwest = { version = "0.11.4", default-features = false, features = ["rustls-tls"] }
rustify = "0.5.2"
reqwest = { version = "0.11.4", default-features = false }
rustify = { version = "0.5.2", default-features = false }
rustify_derive = "0.5.2"
serde = "1.0.130"
serde_json = "1.0.66"
Expand All @@ -38,3 +38,7 @@ test-log = { version = "0.2.8", features = ["trace"] }
tokio = { version = "1.12.0", features = ["full"] }
tokio-test = "0.4.2"
tracing-subscriber = {version = "0.2.17", default-features = false, features = ["env-filter", "fmt"]}

[features]
default = ["reqwest/default-tls", "rustify/default"]
rustls-tls = ["reqwest/rustls-tls", "rustify/rustls-tls"]
11 changes: 8 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ impl ConsulClient {
http_client = http_client.add_root_certificate(cert);
}

// Add client certificate
// Add support for client certificates if rustls-tls is enabled.
#[cfg(feature = "rustls-tls")]
if let (Some(cert), Some(key)) = (&settings.client_cert, &settings.client_key) {
let cert_content =
std::fs::read_to_string(&cert).map_err(|e| ClientError::FileReadError {
Expand Down Expand Up @@ -122,8 +123,8 @@ impl ConsulClient {
///
/// * `address`: CONSUL_HTTP_ADDR
/// * `ca_certs`: CONSUL_CACERT / CONSUL_CAPATH
/// * `client_cert`: CONSUL_CLIENT_CERT
/// * `client_key`: CONSUL_CLIENT_KEY
/// * `client_cert`: CONSUL_CLIENT_CERT, requires `rustls-tls` feature.
/// * `client_key`: CONSUL_CLIENT_KEY, requires `rustls-tls` feature.
/// * `token`: CONSUL_HTTP_TOKEN
/// * `verify`: CONSUL_HTTP_SSL_VERIFY
///
Expand All @@ -136,8 +137,10 @@ pub struct ConsulClientSettings {
pub address: String,
#[builder(default = "self.default_ca_certs()")]
pub ca_certs: Vec<String>,
#[cfg(feature = "rustls-tls")]
#[builder(default = "self.default_client_cert()")]
pub client_cert: Option<String>,
#[cfg(feature = "rustls-tls")]
#[builder(default = "self.default_client_key()")]
pub client_key: Option<String>,
#[builder(setter(into), default = "self.default_token()")]
Expand Down Expand Up @@ -182,6 +185,7 @@ impl ConsulClientSettingsBuilder {
paths
}

#[cfg(feature = "rustls-tls")]
fn default_client_cert(&self) -> Option<String> {
match env::var("CONSUL_CLIENT_CERT") {
Ok(s) => {
Expand All @@ -195,6 +199,7 @@ impl ConsulClientSettingsBuilder {
}
}

#[cfg(feature = "rustls-tls")]
fn default_client_key(&self) -> Option<String> {
match env::var("CONSUL_CLIENT_KEY") {
Ok(s) => {
Expand Down