Skip to content

RUST-732 Mark the versioned API options public. #401

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

Merged
merged 6 commits into from
Jul 26, 2021
Merged
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
26 changes: 15 additions & 11 deletions src/client/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ impl fmt::Display for ServerAddress {
/// Specifies the server API version to declare
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub(crate) enum ServerApiVersion {
pub enum ServerApiVersion {
/// Use API version 1.
V1,
}

Expand Down Expand Up @@ -332,12 +333,13 @@ impl<'de> Deserialize<'de> for ServerApiVersion {
}
}

/// Options used to declare a versioned server API.
/// Options used to declare a versioned server API. For more information, see the [Versioned API](
/// https://docs.mongodb.com/v5.0/reference/versioned-api/) manual page.
#[derive(Clone, Debug, Deserialize, PartialEq, TypedBuilder)]
#[builder(field_defaults(setter(into)))]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub(crate) struct ServerApi {
pub struct ServerApi {
/// The declared API version.
pub version: ServerApiVersion,

Expand Down Expand Up @@ -493,15 +495,17 @@ pub struct ClientOptions {

/// The declared API version for this client.
/// The declared API version is applied to all commands run through the client, including those
/// sent through any [crate::Database] or [crate::Collection] derived from the client.
/// sent through any handle derived from the client.
///
/// Specifying versioned API options in the command document passed to
/// [crate::Database::run_command] AND declaring an API version on the client is not
/// supported and is considered undefined behaviour. To run any command with a different API
/// version or without declaring one, create a separate client that declares the
/// appropriate API version.
#[builder(default, setter(skip))]
pub(crate) server_api: Option<ServerApi>,
/// Specifying versioned API options in the command document passed to `run_command` AND
/// declaring an API version on the client is not supported and is considered undefined
/// behaviour. To run any command with a different API version or without declaring one, create
/// a separate client that declares the appropriate API version.
///
/// For more information, see the [Versioned API](
/// https://docs.mongodb.com/v5.0/reference/versioned-api/) manual page.
#[builder(default)]
pub server_api: Option<ServerApi>,

/// The amount of time the Client should attempt to select a server for an operation before
/// timing outs
Expand Down
26 changes: 16 additions & 10 deletions src/cmap/establish/handshake/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use super::Handshaker;
use crate::{bson::doc, cmap::options::ConnectionPoolOptions, options::DriverInfo};
use crate::{
bson::doc,
cmap::options::ConnectionPoolOptions,
options::{ClientOptions, DriverInfo},
};

#[test]
fn metadata_no_options() {
Expand All @@ -24,15 +28,17 @@ fn metadata_with_options() {
let name = "even better Rust driver";
let version = "the best version, of course";

let options = ConnectionPoolOptions::builder()
.app_name(app_name.to_string())
.driver_info(
DriverInfo::builder()
.name(name.to_string())
.version(version.to_string())
.build(),
)
.build();
let options = ConnectionPoolOptions::from_client_options(
&ClientOptions::builder()
.app_name(app_name.to_string())
.driver_info(
DriverInfo::builder()
.name(name.to_string())
.version(version.to_string())
.build(),
)
.build(),
);

let handshaker = Handshaker::new(Some(options.into()));

Expand Down
10 changes: 6 additions & 4 deletions src/cmap/establish/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tokio::sync::RwLockWriteGuard;
use crate::{
bson::{doc, Bson},
cmap::{establish::Handshaker, Command, Connection, ConnectionPoolOptions},
options::{AuthMechanism, Credential, ReadPreference},
options::{AuthMechanism, ClientOptions, Credential, ReadPreference},
test::{TestClient, CLIENT_OPTIONS, LOCK},
};

Expand Down Expand Up @@ -34,9 +34,11 @@ async fn speculative_auth_test(
.await
.unwrap();

let mut pool_options = ConnectionPoolOptions::builder()
.credential(credential.clone())
.build();
let mut pool_options = ConnectionPoolOptions::from_client_options(
&ClientOptions::builder()
.credential(credential.clone())
.build(),
);
pool_options.tls_options = CLIENT_OPTIONS.tls_options();

let handshaker = Handshaker::new(Some(pool_options.clone().into()));
Expand Down
5 changes: 1 addition & 4 deletions src/cmap/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ use crate::{
};

/// Contains the options for creating a connection pool.
#[derive(Clone, Default, Deserialize, TypedBuilder, Derivative)]
#[derive(Clone, Default, Deserialize, Derivative)]
#[derivative(Debug, PartialEq)]
#[builder(field_defaults(default, setter(into)))]
#[serde(rename_all = "camelCase")]
pub(crate) struct ConnectionPoolOptions {
/// The application name specified by the user. This is sent to the server as part of the
Expand Down Expand Up @@ -74,13 +73,11 @@ pub(crate) struct ConnectionPoolOptions {
/// Whether to start the pool as "ready" or not.
/// For tests only.
#[cfg(test)]
#[builder(setter(skip), default)]
pub(crate) ready: Option<bool>,

/// The declared API version
///
/// The default value is to have no declared API version
#[builder(setter(skip), default)]
pub(crate) server_api: Option<ServerApi>,

/// The options specifying how a TLS connection should be configured. If `tls_options` is
Expand Down
2 changes: 1 addition & 1 deletion src/test/spec/unified_runner/test_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub struct Client {
pub observe_events: Option<Vec<String>>,
pub ignore_command_monitoring_events: Option<Vec<String>>,
#[serde(default)]
pub(crate) server_api: Option<ServerApi>,
pub server_api: Option<ServerApi>,
}

fn default_uri() -> String {
Expand Down