Skip to content

Commit 55fb305

Browse files
committed
Merge branch 'main' into RUST-1529-aws-sdk-signature
2 parents c1b3f82 + c95787f commit 55fb305

File tree

21 files changed

+104
-123
lines changed

21 files changed

+104
-123
lines changed

Cargo.lock

Lines changed: 35 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dns-resolver = ["dep:hickory-resolver", "dep:hickory-proto"]
4141
cert-key-password = ["dep:pem", "dep:pkcs8"]
4242

4343
# Enable support for MONGODB-AWS authentication.
44-
aws-auth = ["dep:reqwest", "aws-config", "aws-types", "aws-credential-types", "aws-sigv4", "http"]
44+
aws-auth = ["dep:reqwest", "dep:aws-config", "dep:aws-types", "dep:aws-credential-types", "dep:aws-sigv4", "dep:http"]
4545

4646
# Enable support for on-demand Azure KMS credentials.
4747
azure-kms = ["dep:reqwest"]

src/action/run_command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Database {
4141
pub fn run_command(&self, command: Document) -> RunCommand {
4242
RunCommand {
4343
db: self,
44-
command: RawDocumentBuf::from_document(&command),
44+
command: RawDocumentBuf::try_from(&command),
4545
options: None,
4646
session: None,
4747
}
@@ -76,7 +76,7 @@ impl Database {
7676
pub fn run_cursor_command(&self, command: Document) -> RunCursorCommand {
7777
RunCursorCommand {
7878
db: self,
79-
command: RawDocumentBuf::from_document(&command),
79+
command: RawDocumentBuf::try_from(&command),
8080
options: None,
8181
session: ImplicitSession,
8282
}

src/bson_compat.rs

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,18 @@ pub(crate) fn cstr_to_str(cs: &CStr) -> &str {
2929
}
3030
}
3131

32+
#[cfg(feature = "bson-3")]
3233
pub(crate) trait RawDocumentBufExt: Sized {
33-
fn append_ref_compat<'a>(
34+
fn append_ref<'a>(
3435
&mut self,
3536
key: impl AsRef<CStr>,
3637
value: impl Into<crate::bson::raw::RawBsonRef<'a>> + 'a,
3738
);
38-
39-
#[cfg(not(feature = "bson-3"))]
40-
fn decode_from_bytes(data: Vec<u8>) -> RawResult<Self>;
4139
}
4240

4341
#[cfg(feature = "bson-3")]
4442
impl RawDocumentBufExt for crate::bson::RawDocumentBuf {
45-
fn append_ref_compat<'a>(
43+
fn append_ref<'a>(
4644
&mut self,
4745
key: impl AsRef<CStr>,
4846
value: impl Into<crate::bson::raw::RawBsonRef<'a>> + 'a,
@@ -51,45 +49,15 @@ impl RawDocumentBufExt for crate::bson::RawDocumentBuf {
5149
}
5250
}
5351

54-
#[cfg(not(feature = "bson-3"))]
55-
impl RawDocumentBufExt for crate::bson::RawDocumentBuf {
56-
fn append_ref_compat<'a>(
57-
&mut self,
58-
key: impl AsRef<CStr>,
59-
value: impl Into<crate::bson::raw::RawBsonRef<'a>>,
60-
) {
61-
self.append_ref(key, value)
62-
}
63-
64-
fn decode_from_bytes(data: Vec<u8>) -> RawResult<Self> {
65-
Self::from_bytes(data)
66-
}
67-
}
68-
69-
#[cfg(not(feature = "bson-3"))]
70-
pub(crate) trait RawDocumentExt {
71-
fn decode_from_bytes<D: AsRef<[u8]> + ?Sized>(data: &D) -> RawResult<&Self>;
72-
}
73-
74-
#[cfg(not(feature = "bson-3"))]
75-
impl RawDocumentExt for crate::bson::RawDocument {
76-
fn decode_from_bytes<D: AsRef<[u8]> + ?Sized>(data: &D) -> RawResult<&Self> {
77-
Self::from_bytes(data)
78-
}
79-
}
80-
81-
#[cfg(not(feature = "bson-3"))]
82-
#[allow(dead_code)]
83-
pub(crate) trait DocumentExt {
84-
fn encode_to_vec(&self) -> crate::bson::ser::Result<Vec<u8>>;
52+
#[cfg(feature = "bson-3")]
53+
pub(crate) trait RawBsonRefExt {
54+
fn to_raw_bson(&self) -> crate::bson::RawBson;
8555
}
8656

87-
#[cfg(not(feature = "bson-3"))]
88-
impl DocumentExt for crate::bson::Document {
89-
fn encode_to_vec(&self) -> crate::bson::ser::Result<Vec<u8>> {
90-
let mut out = vec![];
91-
self.to_writer(&mut out)?;
92-
Ok(out)
57+
#[cfg(feature = "bson-3")]
58+
impl RawBsonRefExt for crate::bson::RawBsonRef<'_> {
59+
fn to_raw_bson(&self) -> crate::bson::RawBson {
60+
(*self).into()
9361
}
9462
}
9563

@@ -113,6 +81,7 @@ use_either! {
11381
RawError => error::Error | raw::Error;
11482
DeError => error::Error | de::Error;
11583
SerError => error::Error | ser::Error;
84+
Utf8Lossy => Utf8Lossy | serde_helpers::Utf8LossyDeserialization;
11685
serialize_to_raw_document_buf => serialize_to_raw_document_buf | to_raw_document_buf;
11786
serialize_to_document => serialize_to_document | to_document;
11887
serialize_to_bson => serialize_to_bson | to_bson;

src/bson_util.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use std::{
66

77
use serde::Serialize;
88

9+
#[cfg(feature = "bson-3")]
10+
use crate::bson_compat::{RawBsonRefExt as _, RawDocumentBufExt as _};
911
use crate::{
1012
bson::{
1113
oid::ObjectId,
@@ -17,7 +19,6 @@ use crate::{
1719
RawBsonRef,
1820
RawDocumentBuf,
1921
},
20-
bson_compat::RawDocumentBufExt as _,
2122
checked::Checked,
2223
error::{Error, ErrorKind, Result},
2324
runtime::SyncLittleEndianRead,
@@ -78,7 +79,7 @@ pub(crate) fn to_bson_array(docs: &[Document]) -> Bson {
7879
pub(crate) fn to_raw_bson_array(docs: &[Document]) -> Result<RawBson> {
7980
let mut array = RawArrayBuf::new();
8081
for doc in docs {
81-
array.push(RawDocumentBuf::from_document(doc)?);
82+
array.push(RawDocumentBuf::try_from(doc)?);
8283
}
8384
Ok(RawBson::Array(array))
8485
}
@@ -215,7 +216,7 @@ pub(crate) fn append_ser(
215216
value: T,
216217
}
217218
let raw_doc = crate::bson_compat::serialize_to_raw_document_buf(&Helper { value })?;
218-
this.append_ref_compat(
219+
this.append_ref(
219220
key,
220221
raw_doc
221222
.get("value")?
@@ -241,7 +242,7 @@ pub(crate) fn get_or_prepend_id_field(doc: &mut RawDocumentBuf) -> Result<Bson>
241242
let new_length: i32 = Checked::new(new_bytes.len()).try_into()?;
242243
new_bytes[0..4].copy_from_slice(&new_length.to_le_bytes());
243244

244-
*doc = RawDocumentBuf::decode_from_bytes(new_bytes)?;
245+
*doc = RawDocumentBuf::from_bytes(new_bytes)?;
245246

246247
Ok(id.into())
247248
}

src/change_stream.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use serde::de::DeserializeOwned;
2020
#[cfg(test)]
2121
use tokio::sync::oneshot;
2222

23+
#[cfg(feature = "bson-3")]
24+
use crate::bson_compat::RawBsonRefExt as _;
2325
use crate::{
2426
change_stream::event::{ChangeStreamEvent, ResumeToken},
2527
cursor::{stream_poll_next, BatchValue, CursorStream, NextInBatchFuture},

src/client/auth/aws.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ use crate::{
2525
serde_util,
2626
};
2727

28-
#[cfg(not(feature = "bson-3"))]
29-
use crate::bson_compat::DocumentExt as _;
30-
3128
#[cfg(feature = "aws-auth")]
3229
use aws_config::BehaviorVersion;
3330

@@ -91,7 +88,8 @@ async fn authenticate_stream_inner(
9188
// channel binding is not supported.
9289
"p": 110i32,
9390
};
94-
let client_first_payload_bytes = client_first_payload.encode_to_vec()?;
91+
let mut client_first_payload_bytes = vec![];
92+
client_first_payload.to_writer(&mut client_first_payload_bytes)?;
9593

9694
let sasl_start = SaslStart::new(
9795
source.into(),
@@ -417,6 +415,16 @@ impl AwsCredential {
417415
}
418416
}
419417

418+
// Creates AwsCredential from keys.
419+
fn from_sdk_creds(creds: Credentials) -> Self {
420+
Self {
421+
access_key_id: creds.access_key_id().to_string(),
422+
secret_access_key: creds.secret_access_key().to_string(),
423+
session_token: creds.session_token().map(|s| s.to_string()),
424+
expiration: None,
425+
}
426+
}
427+
420428
async fn get_from_assume_role_with_web_identity_request(
421429
token_file: String,
422430
role_arn: String,

0 commit comments

Comments
 (0)