-
Notifications
You must be signed in to change notification settings - Fork 178
RUST-1208 Future-proof features #1062
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,46 +27,37 @@ exclude = [ | |
] | ||
|
||
[features] | ||
default = [] | ||
default = ["compat-3-0-0", "rustls-tls", "dns-resolver"] | ||
compat-3-0-0 = [] | ||
sync = [] | ||
openssl-tls = ["openssl", "openssl-probe", "tokio-openssl"] | ||
|
||
# Enable support for v0.4 of the chrono crate in the public API of the BSON library. | ||
bson-chrono-0_4 = ["bson/chrono-0_4"] | ||
|
||
# Enable support for the serde_with crate in the BSON library. | ||
bson-serde_with = ["bson/serde_with"] | ||
|
||
# Enable support for v0.8 of the uuid crate in the public API of the BSON library. | ||
bson-uuid-0_8 = ["bson/uuid-0_8"] | ||
|
||
# Enable support for v1.x of the uuid crate in the public API of the BSON library. | ||
bson-uuid-1 = ["bson/uuid-1"] | ||
rustls-tls = ["dep:rustls", "dep:rustls-pemfile", "dep:tokio-rustls"] | ||
openssl-tls = ["dep:openssl", "dep:openssl-probe", "dep:tokio-openssl"] | ||
dns-resolver = ["dep:trust-dns-resolver", "dep:trust-dns-proto"] | ||
|
||
# Enable support for MONGODB-AWS authentication. | ||
# This can only be used with the tokio-runtime feature flag. | ||
aws-auth = ["reqwest"] | ||
aws-auth = ["dep:reqwest"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice, I think the need to do this will go away in the 2024 edition rust-lang/cargo#12826 |
||
|
||
# Enable support for on-demand Azure KMS credentials. | ||
# This can only be used with the tokio-runtime feature flag. | ||
azure-kms = ["reqwest"] | ||
azure-kms = ["dep:reqwest"] | ||
|
||
# Enable support for on-demand GCP KMS credentials. | ||
# This can only be used with the tokio-runtime feature flag. | ||
gcp-kms = ["reqwest"] | ||
gcp-kms = ["dep:reqwest"] | ||
|
||
zstd-compression = ["zstd"] | ||
zlib-compression = ["flate2"] | ||
snappy-compression = ["snap"] | ||
zstd-compression = ["dep:zstd"] | ||
zlib-compression = ["dep:flate2"] | ||
snappy-compression = ["dep:snap"] | ||
|
||
# Enables support for client-side field level encryption and queryable encryption. | ||
# The In Use Encryption API is unstable and may have backwards-incompatible changes in minor version updates. | ||
in-use-encryption-unstable = ["mongocrypt", "rayon", "num_cpus"] | ||
in-use-encryption-unstable = ["dep:mongocrypt", "dep:rayon", "dep:num_cpus"] | ||
|
||
# Enables support for emitting tracing events. | ||
# The tracing API is unstable and may have backwards-incompatible changes in minor version updates. | ||
# TODO: pending https://github.com/tokio-rs/tracing/issues/2036 stop depending directly on log. | ||
tracing-unstable = ["tracing", "log"] | ||
tracing-unstable = ["dep:tracing", "dep:log"] | ||
|
||
[dependencies] | ||
action_macro = { path = "action_macro" } | ||
|
@@ -95,7 +86,7 @@ percent-encoding = "2.0.0" | |
rand = { version = "0.8.3", features = ["small_rng"] } | ||
rayon = { version = "1.5.3", optional = true } | ||
rustc_version_runtime = "0.2.1" | ||
rustls-pemfile = "1.0.1" | ||
rustls-pemfile = { version = "1.0.1", optional = true } | ||
serde_with = "1.3.1" | ||
sha-1 = "0.10.0" | ||
sha2 = "0.10.2" | ||
|
@@ -107,8 +98,8 @@ take_mut = "0.2.2" | |
thiserror = "1.0.24" | ||
tokio-openssl = { version = "0.6.3", optional = true } | ||
tracing = { version = "0.1.36", optional = true } | ||
trust-dns-proto = "0.21.2" | ||
trust-dns-resolver = "0.21.2" | ||
trust-dns-proto = { version = "0.21.2", optional = true } | ||
trust-dns-resolver = { version = "0.21.2", optional = true } | ||
typed-builder = "0.10.0" | ||
webpki-roots = "0.25.2" | ||
zstd = { version = "0.11.2", optional = true } | ||
|
@@ -125,6 +116,7 @@ features = ["json", "rustls-tls"] | |
|
||
[dependencies.rustls] | ||
version = "0.21.6" | ||
optional = true | ||
features = ["dangerous_configuration"] | ||
|
||
[dependencies.serde] | ||
|
@@ -140,6 +132,7 @@ features = ["io-util", "sync", "macros", "net", "process", "rt", "time"] | |
|
||
[dependencies.tokio-rustls] | ||
version = "0.24.1" | ||
optional = true | ||
features = ["dangerous_configuration"] | ||
|
||
[dependencies.tokio-util] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ mod parse; | |
mod resolver_config; | ||
|
||
use std::{ | ||
borrow::Cow, | ||
cmp::Ordering, | ||
collections::HashSet, | ||
convert::TryFrom, | ||
|
@@ -45,7 +44,10 @@ use crate::{ | |
srv::{OriginalSrvInfo, SrvResolver}, | ||
}; | ||
|
||
#[cfg(feature = "dns-resolver")] | ||
pub use resolver_config::ResolverConfig; | ||
#[cfg(not(feature = "dns-resolver"))] | ||
pub(crate) use resolver_config::ResolverConfig; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use of DNS resolution is ... not neatly encapsulated in the codebase, so to keep this from being a giant refactor PR I made the various machinery crate-internal when the feature is disabled rather than being feature-gated entirely. |
||
|
||
pub(crate) const DEFAULT_PORT: u16 = 27017; | ||
|
||
|
@@ -253,14 +255,16 @@ impl ServerAddress { | |
}) | ||
} | ||
|
||
pub(crate) fn host(&self) -> Cow<'_, str> { | ||
#[cfg(feature = "dns-resolver")] | ||
pub(crate) fn host(&self) -> std::borrow::Cow<'_, str> { | ||
match self { | ||
Self::Tcp { host, .. } => Cow::Borrowed(host.as_str()), | ||
Self::Tcp { host, .. } => std::borrow::Cow::Borrowed(host.as_str()), | ||
#[cfg(unix)] | ||
Self::Unix { path } => path.to_string_lossy(), | ||
} | ||
} | ||
|
||
#[cfg(feature = "dns-resolver")] | ||
pub(crate) fn port(&self) -> Option<u16> { | ||
match self { | ||
Self::Tcp { port, .. } => *port, | ||
|
@@ -597,6 +601,7 @@ pub struct ClientOptions { | |
#[builder(default, setter(skip))] | ||
#[serde(skip)] | ||
#[derivative(Debug = "ignore")] | ||
#[cfg(feature = "dns-resolver")] | ||
pub(crate) resolver_config: Option<ResolverConfig>, | ||
|
||
/// Control test behavior of the client. | ||
|
@@ -932,8 +937,7 @@ impl HostInfo { | |
Ok(match self { | ||
Self::HostIdentifiers(hosts) => ResolvedHostInfo::HostIdentifiers(hosts), | ||
Self::DnsRecord(hostname) => { | ||
let mut resolver = | ||
SrvResolver::new(resolver_config.clone().map(|config| config.inner)).await?; | ||
let mut resolver = SrvResolver::new(resolver_config.clone()).await?; | ||
let config = resolver.resolve_client_options(&hostname).await?; | ||
ResolvedHostInfo::DnsRecord { hostname, config } | ||
} | ||
|
@@ -1264,6 +1268,17 @@ impl ClientOptions { | |
MIN_HEARTBEAT_FREQUENCY | ||
} | ||
} | ||
|
||
pub(crate) fn resolver_config(&self) -> Option<&ResolverConfig> { | ||
#[cfg(feature = "dns-resolver")] | ||
{ | ||
self.resolver_config.as_ref() | ||
} | ||
#[cfg(not(feature = "dns-resolver"))] | ||
{ | ||
None | ||
} | ||
} | ||
} | ||
|
||
/// Splits a string into a section before a given index and a section exclusively after the index. | ||
|
@@ -1359,6 +1374,13 @@ impl ConnectionString { | |
.into()) | ||
} | ||
}; | ||
#[cfg(not(feature = "dns-resolver"))] | ||
if srv { | ||
return Err(Error::invalid_argument( | ||
"mongodb+srv connection strings cannot be used when the 'dns-resolver' feature is \ | ||
disabled", | ||
)); | ||
} | ||
|
||
let after_scheme = &s[end_of_scheme + 3..]; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether giving this feature a generic name is the right way (treating the actual dependency as an internal detail) or if it should just explicitly be called "trust-dns-resolver" in case we want to add other resolver crates in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think I'm in favor of keeping it generic. I was curious what the status of
trust-dns-resolver
was and it looks like they've actually "rebranded" to a different crate (see here) that we might want to switch over to at some point. Keeping the name neutral will make it easier for us to swap out the internal dep.Worst case, if we did want to introduce more resolver crates we could treat this flag as our "default" choice and then allow users to opt into a different one if they want to.